Inputing Data from one form to another

G

Guest

I have a form A where it assignes an ID whenever I start a new entry. I put a
command button to open a new Form B where the ID in Form A is the common
field for both forms. My form B however doesn't link properly and nothing of
my entries from form A will show in Form B.

My code looks like this:

Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_QuoteDetails"

stLinkCriteria = "[OrderInfoID]=" & Me![OrderInfoID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdNext_Click:
Exit Sub

Err_cmdNext_Click:
MsgBox Err.Description
Resume Exit_cmdNext_Click

End Sub

Please Advise.
Thanks in advance
Travis
 
G

Guest

Tdahlman said:
I have a form A where it assignes an ID whenever I start a new entry. I put a
command button to open a new Form B where the ID in Form A is the common
field for both forms. My form B however doesn't link properly and nothing of
my entries from form A will show in Form B.

My code looks like this:

Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_QuoteDetails"

stLinkCriteria = "[OrderInfoID]=" & Me![OrderInfoID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdNext_Click:
Exit Sub

Err_cmdNext_Click:
MsgBox Err.Description
Resume Exit_cmdNext_Click

End Sub

Please Advise.
Thanks in advance
Travis
 
G

Guest

I don't know if Ken answered this or not. His reply looked blank to me which
could just be a bug in the newsreader.

As for your question, it seems that if you create a new record then open a
form linked to that PK, the form will be blank until you have saved the
record. You may need to place a command in your code to force save the
record before opening the second form.

my 2 cents...
 
G

Guest

Travis:

Sorry about the blank post; inadvertently clicked the 'Post' button.

I'm not sure I fully understand what you say, but using the WhereCondition
argument of the OpenForm method will open the second form filtered to those
records where the ID matches the current ID in the first form. It won't
automatically add that ID to new records which you create in the second form.
You have to specifically set the DefaultValue property of the control on the
second form. You can do this by passing the value as the OpenArgs property
of the second form like so:

DoCmd.OpenForm stDocName, , , stLinkCriteria,,,Me.OrderInfoID

or more readably:

DoCmd.OpenForm _
FormName:=stDocName, _
WhereCondition:=stLinkCriteria, _
OpenArgs:=Me.OrderInfoID

In the second form's Open event procedure put:

If Not IsNull(Me.OpenArgs) Then
Me.OrderInfoID.DefaultValue = """" & Me.OpenArgs & """"
End If

The foreign key OrderInfoID in the second form's underlying table must not
be an autonumber field of course, but a straightforward long integer number
data type.

Note that the DefaultValue property of a control is a string expression
regardless of the data type; hence the delimiting literal quotes.

Ken Sheridan
Stafford, England
 

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

Similar Threads


Top