Checking records

G

Guest

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(frmTravel) from that
Individual 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]. This information comes from the
previous forms. Now if the record already exist then
I want it to populate the form from the table tblTravel

This is what I have:

Private Sub btnTravel_Click()
On Error GoTo Err_btnTravel_Click
Dim DocName As String
DocName = "frmTravel"
DoCmd.OpenForm DocName, , , "[Field1]='" & Me.[Field1] & "' AND
[Feild2]='" & Me.[Field2] & "'", , , Me.[Field1] & "$" & Me.[Field2]
Exit_btnTravel_Click:
Exit Sub

Err_btnTravel_Click:
MsgBox Error$
Resume Exit_btnTravel_Click
End Sub

And on the form Travel I have in the load:

Private Sub Form_Load()
If Me.NewRecord Then
Me.[Field1] = split(Me.OpenArgs, "$")(0)
Me.[Field2] = split(Me.OpenArgs, "$")(1)
End If
End Sub



Thank You for any help.....
 
G

Guest

Hi,

Check the record source of the form, run it separatly, can you add records
there?
Mybe the problem is with the record source and not with you code.

Also, to check the code locate the cursor on this line
If Me.NewRecord Then
Press F9, you'll get a red line, that mean that the code will stop there
when you run the form.
Step the code using the F8 key, see if the code move into the next line.
You can check the values in the split(Me.OpenArgs, "$")(0) using the
Immidiate window by writing a question mark and then the variable you want to
check.

?split(Me.OpenArgs, "$")(0)

And then press enter, what value is returned?

To continue the code you can press F5
To remove the code break, locate the cursor again in that line and press F9
again
 

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