Populating FIELDS from another form(s)

G

Guest

I have one form were I create meetings, than another one were the individual
is inputted (all works great - this is not the problem). I am trying to open
a form(Travel) from that form by clicking on a button (This I already have
and that part works). I want the newly opened form (Travel) to automatically
populate a few fields (that you can not see on the form) that are the primary
fields. example: [field1] = Me.[field1] and [field2] = Me.[field2].
Now if the record already exist then I want it to populate the form.

So far I have this:
Private Sub btnTravel_Click()
On Error GoTo Err_btnTravel_Click

Dim DocName As String
DocName = "frmTravel"
DoCmd.OpenForm DocName, , , "[Field1]='" & Me.[Field1] & "' AND
[Field2]='" & Me.[Field2] & "'"

Exit_btnTravel_Click:
Exit Sub

Err_btnTravel_Click:
MsgBox Error$
Resume Exit_btnTravel_Click
End Sub

The way it is working right now is:
1.) If it exist in the table then it comes up
2.) but if it does not exist then the form is blank

What I want is for it to come up both ways:

1.) If it exist in the table then it comes up
2.) but if it does not exist then the form is to be populated by the other
forms putting both fields on the new form so I can add a record.


Please help.

Thank you for any help.
 
G

Guest

I would use a different approach.

I would pass Me.[Field1] and Me.[Field2] using the OpenArgs property. Then
in the form open event or the form load event, use the values passed to check
for a matching record. If found, move to that record or if not found, get the
values from the other forms (that would need to be open) and create a new
record.


HTH
 
G

Guest

I am really new to VBA and was wondering if you could be so kind as to show
me how this might be done...

Thank You for any help

SteveS said:
I would use a different approach.

I would pass Me.[Field1] and Me.[Field2] using the OpenArgs property. Then
in the form open event or the form load event, use the values passed to check
for a matching record. If found, move to that record or if not found, get the
values from the other forms (that would need to be open) and create a new
record.


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Amour said:
I have one form were I create meetings, than another one were the individual
is inputted (all works great - this is not the problem). I am trying to open
a form(Travel) from that form by clicking on a button (This I already have
and that part works). I want the newly opened form (Travel) to automatically
populate a few fields (that you can not see on the form) that are the primary
fields. example: [field1] = Me.[field1] and [field2] = Me.[field2].
Now if the record already exist then I want it to populate the form.

So far I have this:
Private Sub btnTravel_Click()
On Error GoTo Err_btnTravel_Click

Dim DocName As String
DocName = "frmTravel"
DoCmd.OpenForm DocName, , , "[Field1]='" & Me.[Field1] & "' AND
[Field2]='" & Me.[Field2] & "'"

Exit_btnTravel_Click:
Exit Sub

Err_btnTravel_Click:
MsgBox Error$
Resume Exit_btnTravel_Click
End Sub

The way it is working right now is:
1.) If it exist in the table then it comes up
2.) but if it does not exist then the form is blank

What I want is for it to come up both ways:

1.) If it exist in the table then it comes up
2.) but if it does not exist then the form is to be populated by the other
forms putting both fields on the new form so I can add a record.


Please help.

Thank you for any help.
 

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