How to pull multiple field from a form and open another form.

G

Guest

I can do it with one field but how do you do it with say 2 more like
FirstName and LastName?

This is in the current form that will have the value in SSN trasferred to it
Private Sub Form_Load()
If Me.OpenArgs <> "" Then Me.SSN.DefaultValue = Me.OpenArgs
End Sub

This is in the previous form that opens the new form and send the SSN
DoCmd.OpenForm "QLESQ", , , , , , Me!SSN.Value
 
G

Guest

What i provided brings the SSN from 1 form to the next form. This only
brings this one field.

What I needed is how to bring multiple fields such as SSN, Lastname,
Firstname.
 
D

Douglas J Steele

DoCmd.OpenForm "QLESQ", , , , , , Me!FirstName.Value & ";" &
Me!LastName.Value

Then, in QLESQ, use

Private Sub Form_Load()
If Me.OpenArgs <> "" Then
Me.FirstName.DefaultValue = Left(Me.OpenArgs, InStr(Me.OpenArgs, ";") -
1)
Me.LastName.DefaultValue = Mid(Me.OpenArgs, InStr(Me.OpenArgs, ";") +
1)
End If
End Sub

Essentially, you're passing a delimited list as the opening argument, then
breaking it down into its different values in the form's Load event.
 
G

Guest

So how would you ad SSN in there also?


Douglas J Steele said:
DoCmd.OpenForm "QLESQ", , , , , , Me!FirstName.Value & ";" &
Me!LastName.Value

Then, in QLESQ, use

Private Sub Form_Load()
If Me.OpenArgs <> "" Then
Me.FirstName.DefaultValue = Left(Me.OpenArgs, InStr(Me.OpenArgs, ";") -
1)
Me.LastName.DefaultValue = Mid(Me.OpenArgs, InStr(Me.OpenArgs, ";") +
1)
End If
End Sub

Essentially, you're passing a delimited list as the opening argument, then
breaking it down into its different values in the form's Load event.
 
D

Douglas J Steele

DoCmd.OpenForm "QLESQ", , , , , , Me!SSN.Value & ";" & Me!FirstName.Value &
";" &
Me!LastName.Value

Then, in QLESQ, use

Private Sub Form_Load()
Dim varValues As Variant
If Me.OpenArgs <> "" Then
varValues = Split(Me.OpenArgs, ";")
Me.SSN.DefaultValue = varValues(0)
Me.FirstName.DefaultValue = varValues(1)
Me.LastName.DefaultValue = varValues(2)
End If
End Sub
 
J

John Vinson

I can do it with one field but how do you do it with say 2 more like
FirstName and LastName?

This is in the current form that will have the value in SSN trasferred to it
Private Sub Form_Load()
If Me.OpenArgs <> "" Then Me.SSN.DefaultValue = Me.OpenArgs
End Sub

This is in the previous form that opens the new form and send the SSN
DoCmd.OpenForm "QLESQ", , , , , , Me!SSN.Value

If you're trying to transfer the name fields from one table into
another table - DON'T.

Storing data redundantly is essentially NEVER a good idea. Store the
name once, in the names table; if you need it in association with
other data, use a Query linking to it, rather than copying it over.

If you could explain your table structure and why you feel you need to
do this, perhaps we could help.

John W. Vinson[MVP]
 
J

John Vinson

How do you store it into a query from on the current form? and then pull it
on another form?

You don't "store it in a query".

Data is stored in Tables... ONCE.

It sounds like (and since you haven't explained, I may be mistaken
here) that you have one Form based on one Table, with fields for SSN,
FirstName, LastName, etc; and a different Form based on a different
table, also with fields for SSN, FirstName, Lastname, etc.

That is, you are storing the FirstName and LastName redundantly in two
different tables.

If you are doing so... *your table structure is incorrect*. The data
SHOULD NOT EXIST in your second table.

If you just want to *display* the first and last name on the second
Form, without storing them, you can include the FirstName and LastName
in the Combo Box's RowSource query, and put textboxes on the form with
control sources

=cboSSN.Column(n)

where cboSSN is the name of the combo box, and (n) the zero based
subscript of the field containing the name you want displayed. For
example, the RowSource of the combo could be a query

SELECT SSN, FirstName, LastName FROM PeopleTable
ORDER BY SSN;

Its Column Count property would be 3; Bound Column 1 (to store the
SSN); and ColumnWidths could be all nozero so you see the name along
with the SSN when the combo is dropped down.

You'ld have two textboxes on the form with control source

=cboSSN.Column(1)

for the first name, and (2) for the last name.

John W. Vinson[MVP]
 

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