Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd Compile Error

Status
Not open for further replies.

capndave

Technical User
Mar 4, 2003
36
US
I have the following code for an on click event:

Private Sub ViewAvail_Click()
On Error GoTo Err_ViewAvail_Click


Dim stDocName As String

DoCmd.CloseForm "MainMenu"

stDocName = "InventoryAvail"
DoCmd.OpenReport stDocName, acPreview

Exit_ViewAvail_Click:
Exit Sub

I get a a "compile error, method or datamember not found" when button is clicked with the event name highlighted in yellow and the CloseForm highlighted in blue.

If you can help me with this maybe you can also validate my basis for doing this. I have been using macros for the on click events which work fine for me and those with full security access, however when those with only read and execute rights click they get an error "macro not found" or another message about macro new. When I use the above VB without the DoCmd the on click works for all users. I am converting all of the macros to VB to avoid the security issue- does that make sense?

I am a beginner and this forum's FAQ and posting is awesome; thanks to all who have/are helping!!
 
DoCmd.CloseForm??
How about
DoCmd.Close acForm, "FormName" ?

"Rome did not create a great empire by having meetings, they did it by killing all those who opposed them."
 
I am converting all of the macros to VB to avoid the security issue- does that make sense?

Yes, but it is not necessary. You could instead set the security on the macros to allow anyone to execute them. It sounds like a permission problem.

On the other hand, macros are obnoxious in my opinion. If you have to import a form for some reason, you have to import all the macros that are tied to events to get it to work. If the code is on the form, it is portable. Code has alot more functionality too. Most importantly for you, it is a good learning experience to convert it.

As for your error, there is not a close form method. There is a close method...

Code:
DoCmd.Close acForm, "MainMenu", acSaveNo


The third paramter says to not save the form if there are any changes. The default is to prompt, so you can leave it off if that is what you want to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top