Solved

VBA Code to Click Button

Posted on 2008-10-22
40
1,150 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
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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 84
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

821 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