VBA Coding for DoCMD Statements.

C

Curtis

I am running the following code and it works well EXCEPT the "close form"
line doesn't want to work. I am not getting an error message, it just won't
close the form. Is there something misworded here?

Function Another_Record()

MSGBOX "Do you wish to do another LRU update?", 4, "LRU UPDATE"
If vbYes Then
DoCmd.GoToControl "Serial Number"
Else
DoCmd.Close acDefault, , acSaveNo
End If

End Function
 
J

John Spencer

Try

Docmd.Close acForm,,acSaveNo

And to be really safe you might want to specify the name of the form to make
sure the correct object is being closed.

DoCmd.Close acForm,"Name of Form to close",acSaveNo

By the way, this closes the form and does not save any changes made to the
structure of the form. acSaveNo has no effect on whether or not changes to
any data are saved or not.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
F

fredg

I am running the following code and it works well EXCEPT the "close form"
line doesn't want to work. I am not getting an error message, it just won't
close the form. Is there something misworded here?

Function Another_Record()

MSGBOX "Do you wish to do another LRU update?", 4, "LRU UPDATE"
If vbYes Then
DoCmd.GoToControl "Serial Number"
Else
DoCmd.Close acDefault, , acSaveNo
End If

End Function

You need the Message box function, not just a message box to return a
value.
Try it this way:

If MSGBOX("Do you wish to do another LRU update?", 4, "LRU UPDATE") =
vbYes then
DoCmd.GoToControl "Serial Number"
Else
DoCmd.Close acForm, "TheFormName"
End If

acSaveNo is not relevant here as you haven't made any changes to the
form design.
 
J

Jeff Boyce

Answered in the other newsgroup you posted this to.

Please don't post the same question in multiple groups...

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top