Command Button to open form

A

acss

I am trying to open a form through a command button placed on master form. Is
this done event procedure and is it possable to hide the master when the
second is viewed then return when closing the secondary form?
 
D

Dale_Fye via AccessMonster.com

Sure, you would use the command buttons Click event, something like:

Private Sub cmd_OpenForm

me.visible = false
docmd.OpenForm "formName",,,,,acDialog
me.visible = true

End Sub

When you use the "acDialog" parameter in the OpenForm method, you are telling
Access to Open the form and stop running the code in the current module.
Then, when the form is either closed or hidden, then Access will continue
running the code in the current code module. So, setting me.Visible = False
will hide the current form while the new form is visible. When the new form
is closed or hidden, the me.Visible = True will unhide the current form.

HTH
 
D

Dale_Fye via AccessMonster.com

Sure, you would use the command buttons Click event, something like:

Private Sub cmd_OpenForm

me.visible = false
docmd.OpenForm "formName",,,,,acDialog
me.visible = true

End Sub

When you use the "acDialog" parameter in the OpenForm method, you are telling
Access to Open the form and stop running the code in the current module.
Then, when the form is either closed or hidden, then Access will continue
running the code in the current code module. So, setting me.Visible = False
will hide the current form while the new form is visible. When the new form
is closed or hidden, the me.Visible = True will unhide the current form.

HTH
 
A

acss

That works fine and if i may impose on one more thing in that the second form
always resets to the first record while the master maintains the record from
which the command button is activated. Is there some way for the second form
to launch and not resetting to record 1?

Thanks
 
D

Dale_Fye via AccessMonster.com

Yes,

There is a parameter in the OpenForm method for passing it a criteria; it is
the last parameter before the acDialog. What I generally do is declare a
criteria string variable, then I define that just before the OpenForm method

Private Sub cmd_OpenForm

Dim strCriteria as string

strCriteria = "[ID] = " & me.txt_ID
me.visible = false
docmd.OpenForm "formName",,,,strCriteria,acDialog
me.visible = true

End Sub

This assumes you have a numeric ID field associated with the first form and
it is displayed in a control (txt_ID). It also assumes that the form you are
opening has an identical field.

When you use this technique, the new form that is opened will open to the
record corresponding to the current record in your main form.

HTH
Dale
That works fine and if i may impose on one more thing in that the second form
always resets to the first record while the master maintains the record from
which the command button is activated. Is there some way for the second form
to launch and not resetting to record 1?

Thanks
Sure, you would use the command buttons Click event, something like:
[quoted text clipped - 18 lines]
 
A

acss

Actually, the second form is a copy of the first but represents data entry
for a different country so while the main form may be at record 50 the second
form may be at 21 or 22..etc. It would be easier if the second form just
opened up from the last entry that was done on that form. Can this be done?

Dale_Fye via AccessMonster.com said:
Yes,

There is a parameter in the OpenForm method for passing it a criteria; it is
the last parameter before the acDialog. What I generally do is declare a
criteria string variable, then I define that just before the OpenForm method

Private Sub cmd_OpenForm

Dim strCriteria as string

strCriteria = "[ID] = " & me.txt_ID
me.visible = false
docmd.OpenForm "formName",,,,strCriteria,acDialog
me.visible = true

End Sub

This assumes you have a numeric ID field associated with the first form and
it is displayed in a control (txt_ID). It also assumes that the form you are
opening has an identical field.

When you use this technique, the new form that is opened will open to the
record corresponding to the current record in your main form.

HTH
Dale
That works fine and if i may impose on one more thing in that the second form
always resets to the first record while the master maintains the record from
which the command button is activated. Is there some way for the second form
to launch and not resetting to record 1?

Thanks
Sure, you would use the command buttons Click event, something like:
[quoted text clipped - 18 lines]
this done event procedure and is it possable to hide the master when the
second is viewed then return when closing the secondary form?
 

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