combine multiple buttons into 1

krberube

just beyond new
Local time
Yesterday, 19:22
Joined
Jan 14, 2005
Messages
142
I have several buttons on a form used to import data from an ODBC connection.
The code turns off warning messages, turns them back on then a msgbox opens stating "import complete". all these buttons do this when each is clicked.
My question is: Can i combine all this code into 1 button? is the below code correct?

current code for 2 buttons:
Private Sub Command12_Click()
DoCmd.Hourglass True
'Turns off the Access warning messages
DoCmd.SetWarnings False
DoCmd.OpenQuery "SM_1A_HeaderItem cleanup"
DoCmd.Hourglass False
'Turns the Access warning messages back on
DoCmd.SetWarnings True
MsgBox "Import Complete!"
End Sub

Private Sub Command14_Click()
DoCmd.Hourglass True
'Turns off the Access warning messages
DoCmd.SetWarnings False
DoCmd.OpenQuery "AR1_CustomerMaster Cleanup"
DoCmd.Hourglass False
'Turns the Access warning messages back on
DoCmd.SetWarnings True
MsgBox "Import Complete!"
End Sub


proposed code for 1 button:

Private Sub NEWBUTTON()
DoCmd.Hourglass True
'Turns off the Access warning messages
DoCmd.SetWarnings False
DoCmd.OpenQuery "SM_1A_HeaderItem cleanup"
DoCmd.OpenQuery "AR1_CustomerMaster Cleanup"
DoCmd.Hourglass False
'Turns the Access warning messages back on
DoCmd.SetWarnings True
MsgBox "Import Complete!"
End Sub
 
Looks ok to me- did you run into any problems?
 
seems to have worked fine. Did it in a test DB first.
Thanks
 

Users who are viewing this thread

Back
Top Bottom