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

Hi Dirk,

A BIG Thankyou - I got it working...

Thanks heaps for your help

"Dirk Goldgar" wrote:

"GLT" wrote in message
...
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?


No. You should not have made a new public sub in a standard module. Delete
that sub, and the module if you created one just for that purpose.

Instead, open the form frm01_Services in Design View, open its code module
in the VB Editor, and locate the existing command button's event procedure,
which will have the declaration line,

Private Sub cmdGetServicesData_Click()

Change that line to:

Public Sub cmdGetServicesData_Click()

Save and close the form.

** Note: if the command button doesn't have a VBA event procedure, this
whole procedure is not going to work, and you won't be able to
programmatically "click" the button.

Now go to the code on the form where you wanted to call the procedure, and
change this:

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


... to this:

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

Note: you originally had form references in the form,
"Forms.frm01_Services". That's not strictly correct, though it works in
some versions of Access, and I've changed it to "Forms!frm01_Services".

With these changes it ought to work -- if I've understood your setup
correctly.

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

(please reply to the newsgroup)