Passing Info from One Form to another

J

JAguirre

I am opening a form (form 2) from a form (form 1) via a command button for
data entry purposes. I would like form 1 to pass the ID number to form 2.

This works automatically in subforms, but … I can’t get it to work when
opening a separate form. Any help is appreciated.
 
F

fredg

I am opening a form (form 2) from a form (form 1) via a command button for
data entry purposes. I would like form 1 to pass the ID number to form 2.

This works automatically in subforms, but ¡K I can¡¦t get it to work when
opening a separate form. Any help is appreciated.

And do what with it in Form2?
You've asked a very generalized question, so all I can do is give you
a very generalized answer.

Code a Form1 command button Click event:
DoCmd.OpenForm "Form2", , , , , , Me![ID]

Code the Form2 Load event:
If Not IsNull(Me.OpenArgs) Then
MsgBox Me.OpenArgs
End If
 
J

John W. Vinson

I am opening a form (form 2) from a form (form 1) via a command button for
data entry purposes. I would like form 1 to pass the ID number to form 2.

This works automatically in subforms, but … I can’t get it to work when
opening a separate form. Any help is appreciated.

You'll need a bit of code to do this. In your command button code there is a
line resembling

DoCmd.OpenForm strDocument, <maybe some other stuff>

Edit this line by adding

, OpenArgs := Me.ID

using the name of the control on your form which contains the ID value.

Then in the second form's Open event put code like

Private Sub Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then
Me!ID.DefaultValue = Me.OpenArgs
End If
End Sub

You'll probably also want to set the WhereCondition argument of the OpenForm
method, if it's not being set in your code already - post the Click event code
if you need help.
 
J

JAguirre

Thx John. I actually fixed this using a BeforeInsert event on form2 to
capture the ID# on form1. Don't know why I didn't think of this before -
sometimes the obvious eludes. Thx again!
 

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