A
Amour
I am really new to VBA, currently 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 and does not show any of
the options to enter data.
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.
I might even take a different approach.
By passing Me.[Field1] and Me.[Field2] using the OpenArgs property. Then
in the form open event or the form load event, I could 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.
I really don't understand how to do this and was wondering if someone could
be so kind as to show me how this might be done...
Please help.
Thank you for any help.
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 and does not show any of
the options to enter data.
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.
I might even take a different approach.
By passing Me.[Field1] and Me.[Field2] using the OpenArgs property. Then
in the form open event or the form load event, I could 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.
I really don't understand how to do this and was wondering if someone could
be so kind as to show me how this might be done...
Please help.
Thank you for any help.