Solved

VBA Code to Click Button

Posted on 2008-10-22
40
1,178 Views
Last Modified: 2010-08-05
I have a button in my form to Delete Record.  I would like to write some code so that when I click abother button it clicks the Delete Record button - or is there some code I can use to delete the curretn record?
0
Comment
Question by:Powerhousecomputing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 21
  • 13
  • 5
  • +1
40 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22776265
in the other button

private sub OtherButton_click()
cmdDeleteButton_click
end sub


cmdDeleteButton is the name of the delete record button
0
 
LVL 46

Expert Comment

by:tbsgadi
ID: 22776301
Hi Powerhousecomputing,

Add
Run cmdDelete_Click
 to the end of your code, where CmdDelete is the name of your delete button


Good Luck!

Gary
0
 

Author Comment

by:Powerhousecomputing
ID: 22776306
It doesn't like that coding - my Delete buitton is called DeleteRecord
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:Powerhousecomputing
ID: 22776312
Run cmdDeleteRecord_click

doesn't like it!
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22776337



private sub OtherButton_click()
DeleteRecord_click
end sub
0
 

Author Comment

by:Powerhousecomputing
ID: 22776366
Is it possible for it to ask IF I want to delete the rercord first?
0
 

Author Comment

by:Powerhousecomputing
ID: 22776413
still does not like Run cmdDeleteRecord_click
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22776466
Powerhousecomputing,

why don't you try this


           DeleteRecord_click
0
 

Author Comment

by:Powerhousecomputing
ID: 22776467
Ok - here is my code -

Private Sub Validate_Click()
If DCount("[first name]", "Audition Applications", "[first name]=" & Chr(34) & Me.[first name] & Chr(34) & " and [surname]=" & Chr(34) & Me.[Surname] & Chr(34) & " and [date of birth]=#" & Me.[date of birth] & "#") > 0 Then

MsgBox "Applicant Already Entered - Record will now be DELETED"
Me.Validated_OK_Label.Visible = False
Run cmdDeleteRecord_click
Else

MsgBox "VALIDATE OK"
Me.Validated_OK_Label.Visible = True
DoCmd.RunMacro "Validate Macro"
End If
End Sub
0
 

Author Comment

by:Powerhousecomputing
ID: 22776488
still not working!
0
 
LVL 46

Expert Comment

by:tbsgadi
ID: 22776515
instead of Run cmdDeleteRecord_click try Run DeleteRecord_click
0
 

Author Comment

by:Powerhousecomputing
ID: 22776553
nope!
0
 
LVL 46

Expert Comment

by:tbsgadi
ID: 22776601
can you post your code for DeleteRecord_click
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22776615

Powerhousecomputingare you reading my posts http:#a22776337http:#a22776466
0
 

Author Comment

by:Powerhousecomputing
ID: 22776631
i have tried all of the above
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22776691

post the codes for the Delete record button
0
 

Author Comment

by:Powerhousecomputing
ID: 22776698
can I use some code instead to delete current record?
0
 

Author Comment

by:Powerhousecomputing
ID: 22776711
Private Sub Validate_Click()
If DCount("[first name]", "Audition Applications", "[first name]=" & Chr(34) & Me.[first name] & Chr(34) & " and [surname]=" & Chr(34) & Me.[Surname] & Chr(34) & " and [date of birth]=#" & Me.[date of birth] & "#") > 0 Then

MsgBox "Applicant Already Entered - You will now be asked if you wish to DELETE the record - ONLY DELETE IF THIS IS A NEW RECORD"
Me.Validated_OK_Label.Visible = False
DeleteRecord_click
Else

MsgBox "VALIDATE OK"
Me.Validated_OK_Label.Visible = True
DoCmd.RunMacro "Validate Macro"
End If
End Sub
0
 
LVL 85
ID: 22776715
Are you working with a Form/Subform setup? If so, is the button you're trying to "click" on the SAME FORM as your Validate button?
0
 

Author Comment

by:Powerhousecomputing
ID: 22776738
The button is on the same form - it is called DeleteRecord and is a system button
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22776753
WHY CAN'T you post the codes for the DELETE RECORD BUTTON?

change

private deleterecord_click()

to

PUBLIC deleterecord_click()
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22776780


with the codes you posted

DELETE IF THIS IS A NEW RECORD"
Me.Validated_OK_Label.Visible = False

DeleteRecord_click  '<<< the word click would have been changed to Proper case  Click if the button name is correct


Else
0
 

Author Comment

by:Powerhousecomputing
ID: 22776896
the Delete record button us an embedded macro apparently!

yes the button name is correct
0
 

Author Comment

by:Powerhousecomputing
ID: 22776906
as you can see this line of code is part of some other code
0
 
LVL 46

Expert Comment

by:tbsgadi
ID: 22776931
You need to look in the properties of the button for the macro it runs.
0
 

Author Comment

by:Powerhousecomputing
ID: 22776968
The Macro is an embedded one and is called:  Audition Appilcations:DeleteRecord:On Click
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22777006
you have to *CONVERT* that embedded macro to vba to be able to access it from the click of another button.
0
 

Author Comment

by:Powerhousecomputing
ID: 22777019
aha!  How do I do that?
0
 

Author Comment

by:Powerhousecomputing
ID: 22777054
ok - I did a Save As

So now presumably I write:

DoCmd.RunMacro (Delete_Record_Macro)

?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22777063
or you can try this


docmd.runmacro " Audition Appilcations:DeleteRecord:On Click"




or could be there are some typo error




docmd.runmacro " Audition Applications:DeleteRecord:On Click"







0
 

Author Comment

by:Powerhousecomputing
ID: 22777085
sorry I don't get it now - I have just called the Macro Delete Record Macro which is what is in the control source so surely I have to call it that now on the code?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22777178
wait a while...
in the design view of the form, select the delete button hit F4
select the event tab, see what is written on the  On Click

post it here

0
 

Author Comment

by:Powerhousecomputing
ID: 22777301
Delete Record Macro
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22777362
ok try this


docmd.runmacro "Delete Record Macro"
0
 

Author Comment

by:Powerhousecomputing
ID: 22777389
Yay - it worked!  Not sure why it didn't a minute ago!

Is it possible for it to ask IF I want to delete the rercord first?
0
 
LVL 46

Expert Comment

by:tbsgadi
ID: 22777390
try instead of DeleteRecord_click

DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22777456
(Is it possible for it to ask IF I want to delete the rercord first?)

just put a msgbox before the  docmd.runmacro "Delete Record Macro" line


if (msgbox("Do you want to delete the record?",vbyesno))=vbyes then

docmd.runmacro "Delete Record Macro"
else

msgbox "Deletion cancelled"

end if
0
 

Author Comment

by:Powerhousecomputing
ID: 22777514
mmm... not sure how that will work - my code is now:

Private Sub Validate_Click()
If DCount("[first name]", "Audition Applications", "[first name]=" & Chr(34) & Me.[first name] & Chr(34) & " and [surname]=" & Chr(34) & Me.[Surname] & Chr(34) & " and [date of birth]=#" & Me.[date of birth] & "#") > 0 Then

MsgBox "Applicant Already Entered - You will now be asked if you wish to DELETE the record - ONLY DELETE IF THIS IS A NEW RECORD"
Me.Validated_OK_Label.Visible = False
If (MsgBox("Are you sure you want to DELETE this record?", vbYesNo)) = vbYes Then
DoCmd.RunMacro "Delete Record Macro"
Else

MsgBox "VALIDATE OK"
Me.Validated_OK_Label.Visible = True
DoCmd.RunMacro "Validate Macro"
End If
End If
End Sub

What is supposed to happen is if it does not validate then it asks if you want to delete, if it does validate than it says OK etc.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 22777582
Powerhousecomputing,

when you insert lines of codes, make sure you don't omit anything
0
 

Author Comment

by:Powerhousecomputing
ID: 22777637
Good point - that's me trying to be clever!  Thank so much!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question