• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1228
  • Last Modified:

VBA Code to Click Button

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
Powerhousecomputing
Asked:
Powerhousecomputing
  • 21
  • 13
  • 5
  • +1
1 Solution
 
Rey Obrero (Capricorn1)Commented:
in the other button

private sub OtherButton_click()
cmdDeleteButton_click
end sub


cmdDeleteButton is the name of the delete record button
0
 
tbsgadiCommented:
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
 
PowerhousecomputingAuthor Commented:
It doesn't like that coding - my Delete buitton is called DeleteRecord
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
PowerhousecomputingAuthor Commented:
Run cmdDeleteRecord_click

doesn't like it!
0
 
Rey Obrero (Capricorn1)Commented:



private sub OtherButton_click()
DeleteRecord_click
end sub
0
 
PowerhousecomputingAuthor Commented:
Is it possible for it to ask IF I want to delete the rercord first?
0
 
PowerhousecomputingAuthor Commented:
still does not like Run cmdDeleteRecord_click
0
 
Rey Obrero (Capricorn1)Commented:
Powerhousecomputing,

why don't you try this


           DeleteRecord_click
0
 
PowerhousecomputingAuthor Commented:
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
 
PowerhousecomputingAuthor Commented:
still not working!
0
 
tbsgadiCommented:
instead of Run cmdDeleteRecord_click try Run DeleteRecord_click
0
 
PowerhousecomputingAuthor Commented:
nope!
0
 
tbsgadiCommented:
can you post your code for DeleteRecord_click
0
 
Rey Obrero (Capricorn1)Commented:

Powerhousecomputingare you reading my posts http:#a22776337http:#a22776466
0
 
PowerhousecomputingAuthor Commented:
i have tried all of the above
0
 
Rey Obrero (Capricorn1)Commented:

post the codes for the Delete record button
0
 
PowerhousecomputingAuthor Commented:
can I use some code instead to delete current record?
0
 
PowerhousecomputingAuthor Commented:
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
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
PowerhousecomputingAuthor Commented:
The button is on the same form - it is called DeleteRecord and is a system button
0
 
Rey Obrero (Capricorn1)Commented:
WHY CAN'T you post the codes for the DELETE RECORD BUTTON?

change

private deleterecord_click()

to

PUBLIC deleterecord_click()
0
 
Rey Obrero (Capricorn1)Commented:


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
 
PowerhousecomputingAuthor Commented:
the Delete record button us an embedded macro apparently!

yes the button name is correct
0
 
PowerhousecomputingAuthor Commented:
as you can see this line of code is part of some other code
0
 
tbsgadiCommented:
You need to look in the properties of the button for the macro it runs.
0
 
PowerhousecomputingAuthor Commented:
The Macro is an embedded one and is called:  Audition Appilcations:DeleteRecord:On Click
0
 
Rey Obrero (Capricorn1)Commented:
you have to *CONVERT* that embedded macro to vba to be able to access it from the click of another button.
0
 
PowerhousecomputingAuthor Commented:
aha!  How do I do that?
0
 
PowerhousecomputingAuthor Commented:
ok - I did a Save As

So now presumably I write:

DoCmd.RunMacro (Delete_Record_Macro)

?
0
 
Rey Obrero (Capricorn1)Commented:
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
 
PowerhousecomputingAuthor Commented:
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
 
Rey Obrero (Capricorn1)Commented:
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
 
PowerhousecomputingAuthor Commented:
Delete Record Macro
0
 
Rey Obrero (Capricorn1)Commented:
ok try this


docmd.runmacro "Delete Record Macro"
0
 
PowerhousecomputingAuthor Commented:
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
 
tbsgadiCommented:
try instead of DeleteRecord_click

DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
0
 
Rey Obrero (Capricorn1)Commented:
(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
 
PowerhousecomputingAuthor Commented:
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
 
Rey Obrero (Capricorn1)Commented:
Powerhousecomputing,

when you insert lines of codes, make sure you don't omit anything
0
 
PowerhousecomputingAuthor Commented:
Good point - that's me trying to be clever!  Thank so much!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 21
  • 13
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now