Copy Field Value from Form A to Form B isn't working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello:

I have a test form where I want to copy the value of StudentID [TEXT field]
from the current record to another form. I tried the following code and I
keep getting a 2501 error message.

Private Sub OpenFrmTest_Click()
DoCmd.OpenForm "frmTest", , , "[StudentID] = " & Me.StudentID
End Sub

If I remove the 3 commas and the StudentID info, this part of the code opens
the form, so I know that’s working.

DoCmd.OpenForm "frmTestâ€

Thanks,
Robert
 
That error can be deceiving. First, check to see that StudedtID is a field
in the record source for frmTest. Also, the way the code is written, it is
expecting the field StudentID is a numeric field. If StudentID is text, the
correct syntax should be

DoCmd.OpenForm "frmTest", , , "[StudentID] = '" & Me.StudentID & "'"
 
Hi Klatuu:

Yes, StudentID is a text field with a width of 5 characters on both forms. I
used the following:

DoCmd.OpenForm "frmTest", , , "[StudentID] = '" & Me.StudentID & "'"

The error message disappeared and frmTest opened properly, however, the
StudentID field was blank. What am I failing to do?

Thanks,
Robert
 
Is it the only empty control on the form? or is this a new student and you
are wanting to enter info on the student?
Is the control source of the studentid control set correctly?
Is the form set for data entry or does it allow edits?
 
Klatuu:

It is a totally empty form for a new student, waiting for data to be entered
in all fields. So to answer your questions, every field is empty. I just
manually entered a new record to make sure everything was working properly
and it is.

StudentID is a text field named StudentID.

Robert
 
Here is another thing to check. If this is a brand new studentid created in
the first form, do you requery the first form so the new studentid record is
actually in the table?
 
Klatuu

The first table is tblStudents and all of the records are and have been in
the table for a couple of weeks. I went through the records, randomly stopped
at a student, and then clicked on the cmdbutton to open frmTest.

The second table is a table that holds class information.
ClassID is the first field and StudentID is the 2nd field.

Robert
 
If there are multiple records in the Class table for a student, then passing
the Student ID should take you to the first record in the Class table for
that student. I don't know what else to look for without having the database
in front of me. If you have the record selector box on the second form
visible, what is the value in it when the second form opens?
 
Klatuu:

OK, the following may give you a clue as to what's happening in the second
form which I created solely for this little exercise.

There are no records visible in frmTest.
All fields in the current record are empty.
The blinking cursor is in the first field.
Of the 5 arrows on the bottom of the form, the new record button is grayed
out as is the next and previous buttons.
The first and last button are not grayed out, however, clicking on them does
nothing.
It also says of 1[filtered).

If I choose to do so, I can manually enter a new record into the form.

Does the above help?

Robert
 

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

Back
Top