View Single Post
  #3  
Old February 11th, 2010, 05:57 PM posted to microsoft.public.access.forms
GLT
external usenet poster
 
Posts: 154
Default Clicking a button via VBA

Hi Dirk,

Thanks for your reply, from reading your reply and other posts, I have done
the following:

1) Created a Public Sub module wioth the following:

Public Sub cmdGetServicesData_Click()

Forms!frm01_Services.cmdGetServicesData_Click

End Sub

2) My original code (mistake amended):

Private Sub Form_DblClick(Cancel As Integer)

DoCmd.OpenForm "frm01_Services"
Forms.frm01_Services.cmbServer.Value = Me!Server
Call cmdGetServicesData_Click

End Sub

When I try to run the above, I get a run-time error 2465,
application-defined or object defined error. Am i putting the code in the
correct places?


"Dirk Goldgar" wrote:

"GLT" wrote in message
news
Hi,

I am trying to (using VBA), open a form, populate a combo box, and then
clicka button on the newly opened form...

I have tried the following:

DoCmd.OpenForm "frm01_Services"

Forms.frm01_Services.cmbServer.Value = Me!Server
Forms.frm01_Services.cmdGetServicesData.SetFocus
Forms!frm01_Services.cmbserver_Click -----Error

Line # 3 bombs - is there a function in access that allows me to do this?



You have to modify the definition of the event procedure, in the module of
the form containing it, to make the procedure Public instead of Private. I
think in this line:

Forms!frm01_Services.cmbserver_Click -----Error


... you probably meant "cmdGetServicesData_Click", since that looks
"cmdGetServicesData" should be the name of your command button. But it
still won't work unless you modify the declaration to be like this:

Public Sub cmdGetServicesData_Click()

Then you should be able to call it like this:

Forms!frm01_Services.cmdGetServicesData_Click

You don't even have to SetFocus to the button, since you are calling the
procedure directly.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)