Opening a form to a specific record

B

Beth

I have a form, frmGrades, where I input student grades. The form has a
field listing each student by id number in a limited to list combo box.
When I type a student id in the box and that student isn't in the database,
I want to capture the id I just typed, add it to the students table, and
then open my students form (frmStudents) to the newly added student's record
so I can add their name, etc.
Right now I have code that captures the value and adds the student to the
students table, and it opens the students form, but I can't get to to go to
the new student's record. I have the form opening modal so that when the
student form is closed and you return to the main grades form, it runs a
refresh and few other steps for validating.
Below is a sample of the code up to the steps where I return from the
student form.

Can anyone tell me what I am doing wrong?
Thanks,
Beth


Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String

strMsg = "'" & NewData & "' is not a listed student. Click yes to add
this student."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("Students", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!StudentID = NewData
rs.Update
rs.Close
Set rs = Nothing
Set db = Nothing
DoCmd.OpenForm "frmStudents", , , "StudentID = NewData", , acDialog
 
K

Keith Wilby

Beth said:
I have a form, frmGrades, where I input student grades. The form has a
field listing each student by id number in a limited to list combo box.
When I type a student id in the box and that student isn't in the database,
I want to capture the id I just typed, add it to the students table, and
then open my students form (frmStudents) to the newly added student's
record so I can add their name, etc.
Right now I have code that captures the value and adds the student to the
students table, and it opens the students form, but I can't get to to go
to the new student's record.

So the new record is there but you just can't navigate to it? Have you
tried using the FindRecord method? You could pass the ID number to the form
in the OpenArgs.

HTH - Keith.
www.keithwilby.com
 
B

Beth

Since I am opening in the form in dialog mode, it seems to cancel any record
navigation or using the find method when the form opens. As a side note,
the form has an open event that sets some default values in the form based
on the user's configuration. Those are also bypassed.
I think I could get it to all work if I didn't use the dialog form, but then
I lose the ability to "pause" the rest of the code until I close the form.
I am open to suggestions.
Beth
 

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

Similar Threads

NotInList not firing ? 1
Form sizing issue 1
Access linking new student form to new course form 2
Help With Code Please 5
NotinList problem 7
Not In List 2 values 5
Combo Box to add items to a table 4
Not in list requery issue 4

Top