Function and Syntax problems

C

Confused

I need assistance with the proper syntax for auto-filling the id field on one
form coming from the id field of another form. I believe the function I need
to use is Dlast. Here is the situation. I have several tables which are all
related on the ID field. In the TblIssues (My main table) the ID field is an
autonumber. All my tables have separate forms created. The FrmIssues (the
main form) has a combo box which depending on the selection will open the
appropriate accompanying form. The coding is as follows:

Private Sub Combo22_Change()

DoCmd.RunCommand acCmdSaveRecord

If (Forms!FrmIssues!Combo22 = "Ordering") Then
DoCmd.OpenForm "FrmOrder", acNormal, "", "", , acNormal
End If

If (Forms!FrmIssues!Combo22 = "Service Call") Then
DoCmd.OpenForm "FrmServiceCall", acNormal, "", "", , acNormal

End If

End Sub

What I need is when the accompanying form opens have the ID field on the
form populate automatically with the record ID from the main form so the new
records will be linked.

Any help is greatly appreciated!
 
C

Carl Rapson

Confused said:
I need assistance with the proper syntax for auto-filling the id field on
one
form coming from the id field of another form. I believe the function I
need
to use is Dlast. Here is the situation. I have several tables which are
all
related on the ID field. In the TblIssues (My main table) the ID field is
an
autonumber. All my tables have separate forms created. The FrmIssues
(the
main form) has a combo box which depending on the selection will open the
appropriate accompanying form. The coding is as follows:

Private Sub Combo22_Change()

DoCmd.RunCommand acCmdSaveRecord

If (Forms!FrmIssues!Combo22 = "Ordering") Then
DoCmd.OpenForm "FrmOrder", acNormal, "", "", , acNormal
End If

If (Forms!FrmIssues!Combo22 = "Service Call") Then
DoCmd.OpenForm "FrmServiceCall", acNormal, "", "", , acNormal

End If

End Sub

What I need is when the accompanying form opens have the ID field on the
form populate automatically with the record ID from the main form so the
new
records will be linked.

Any help is greatly appreciated!

Why do you have 'acNormal' in the OpenArgs parameter in your OpenForm calls?

If the main for is already positioned on the record whose ID you want, you
could just pass the ID value in the OpenArgs parameter of OpenForm, and then
pick it up in the next form's Open or Load event:

DoCmd.OpenForm "FrmOrder", acNormal, , , , Me.ID

Carl Rapson
 
C

Confused

Carl,

The reason the syntax is in the format it is, because I was orginally
running this from a macro. I converted the marco to Visual and this was the
result. I want the ID to be passed from the main form to the form opened by
the selection in the combo box. My developers guide was stolen and I dont
currently get the proper formatting of the syntax for passing the ID. I do
believe I have to store it before it can be passed, right? This is where I
am stuck. I have not been do this very long so this is a new undertaking for
me. The Me.ID is where the ID is stored? On the form's Open or Load event
would have additional syntax? Any assistance is always appreciated.

Bob
 
C

Carl Rapson

Confused said:
Carl,

The reason the syntax is in the format it is, because I was orginally
running this from a macro. I converted the marco to Visual and this was
the
result. I want the ID to be passed from the main form to the form opened
by
the selection in the combo box. My developers guide was stolen and I dont
currently get the proper formatting of the syntax for passing the ID. I
do
believe I have to store it before it can be passed, right? This is where
I
am stuck. I have not been do this very long so this is a new undertaking
for
me. The Me.ID is where the ID is stored? On the form's Open or Load event
would have additional syntax? Any assistance is always appreciated.

Bob

If you're wanting to limit the opened form to only records corresponding to
the ID of the current record in the main form, the easiest way to do that
would be something like:

DoCmd.OpenForm "frmOrder", acNormal, , "[ID]=" & Me.ID

This assumes the field is named ID in both tables. What this will do is open
frmOrder with a record source limited to those with a matching ID value.
There's no need to store the ID value anywhere else, and there's no need to
do anything in the Open or Load event of frmOrder (ignore what I posted
before).


Carl Rapson
 
C

Confused

Carl,

I am able to call the ID number from the form as I wanted. Thank you for
your assistance. I am wondering however that if I wanted to have the main
form close when the order opens how would I go about calling the last ID
number from the main table using a text box. I do apologize for waiting so
long to reply but I was called away on a personal matter.

Thank You,
Bob

Carl Rapson said:
Confused said:
Carl,

The reason the syntax is in the format it is, because I was orginally
running this from a macro. I converted the marco to Visual and this was
the
result. I want the ID to be passed from the main form to the form opened
by
the selection in the combo box. My developers guide was stolen and I dont
currently get the proper formatting of the syntax for passing the ID. I
do
believe I have to store it before it can be passed, right? This is where
I
am stuck. I have not been do this very long so this is a new undertaking
for
me. The Me.ID is where the ID is stored? On the form's Open or Load event
would have additional syntax? Any assistance is always appreciated.

Bob

If you're wanting to limit the opened form to only records corresponding to
the ID of the current record in the main form, the easiest way to do that
would be something like:

DoCmd.OpenForm "frmOrder", acNormal, , "[ID]=" & Me.ID

This assumes the field is named ID in both tables. What this will do is open
frmOrder with a record source limited to those with a matching ID value.
There's no need to store the ID value anywhere else, and there's no need to
do anything in the Open or Load event of frmOrder (ignore what I posted
before).


Carl Rapson
 

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