What code opens form?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I now have a command button to open a form using macro (with Echo set to No),
but I think it would be clearer and easier to improve by using code instead.
What would be the lines that do the job? Thanks

Regards,
Sam
 
Sam -

If you just want one code to open a form named, say "frmMenu1", you could
use

DoCmd.OpenForm "frmMenu1"

But if you want to generalize the open form parameters and include error
trapping, you could use

Private Sub cmdOpenfrmMenu1_Click()
On Error GoTo Err_cmdOpenMenu1_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmMenu1"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenMenu1_Click:
Exit Sub

Err_cmdOpenMenu1_Click:
MsgBox Err.Description
Resume Exit_cmdOpenMenu1_Click

End Sub


You can also use the command button wizard in design view to write code for
a command button to open a form. If you do, it will generate code like the
above.

Hope this helps.

Paul
 
Hi Paul,
I just tried your suggestion and it opens form alright. But i'd see two
forms for a split of a second, while it's switching bewteen forms.

Do you know what'd be the equivalent line of the macro action, Echo = No ?

Regards,
Sam
 
Do you know what'd be the equivalent line of the macro action, Echo = No ?

Sam - I copied the following straight out of Access VBA Help for the Echo
method first as it applies to the Application object, followed by the DoCmd
object:
The following example uses the Echo method to prevent the screen from being
repainted while certain operations are underway. While the procedure opens a
form and minimizes it, the user only sees an hourglass icon indicating that
processing is taking place, and the screen isn't repainted. When this task
is completed, the hourglass changes back to a pointer and screen repainting
is turned back on.
Public Sub EchoOff()

' Open the Employees form minimized.
Application.Echo False
DoCmd.Hourglass True
DoCmd.OpenForm "Employees", acNormal
DoCmd.Minimize
Application.Echo True
DoCmd.Hourglass False

End SubAs it applies to the DoCmd object.

The following example uses the Echo method to turn echo off and display the
specified text in the status bar while Visual Basic code is executing:

DoCmd.Echo False, "Visual Basic code is executing."Hope this is helpful.Paul
 
Back
Top