A simple way to start the learning process with Access VBA is to use the built in wizards, such as the command button wizard to accomplish a task, like opening a form, then go into the code and look to see what Access has done. Here's an example of the code the wizard would generate for this task, if the button's name was
OpenFormButton and the form to be opened was
Form1:
- Private Sub OpenFormButton_Click()
-
On Error GoTo Err_OpenFormButton_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "Form1"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_OpenFormButton_Click:
-
Exit Sub
-
-
Err_OpenFormButton_Click:
-
MsgBox Err.Description
-
Resume Exit_OpenFormButton_Click
-
-
End Sub
-
Now you can see the appropriate code, and even more importantly, you see how error handling is done.
But be aware that Access is sometimes lazy. If you try this and the code looks something like this
- DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
-
reseach further for other ways to accomplish your task! Using the Menu items, as this type code does, is not the best practise. This type of code is probably on the way out and may not be supported in future editions of Access.
A note on your message to be displayed while your query is running: many times these messages are thought to be "not displaying" when, in fact, the queries simply run so quickly that the message comes and goes faster than the human eye can process it!
Welcome to TheScripts!
Linq
;0)>