A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Clicking a button via VBA



 
 
Thread Tools Display Modes
  #1  
Old February 11th, 2010, 05:10 PM posted to microsoft.public.access.forms
GLT
external usenet poster
 
Posts: 154
Default Clicking a button via VBA

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?

Any help is always greatly appreciated...

Cheers,
GLT.

Ads
  #2  
Old February 11th, 2010, 05:18 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Clicking a button via VBA

"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)

  #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)

  #4  
Old February 11th, 2010, 06:17 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Clicking a button via VBA

"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)

  #5  
Old February 11th, 2010, 07: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)

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:54 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright 2004-2018 OfficeFrustration.
The comments are property of their posters.