Go To Specific Record after Requery

L

legere864

I have a main form . . . frmStudentEnrollment

I have a pop-up form . . . frmPhotoEntry

When the user wants to add a photograph to the main form, they click on a
button that opens the popup. When the popup opens the Win Open/Save window
opens to allow the user to select the photo. When the user has selected the
photo, they click a button to close the popup and save the file path to the
recordset. Here's the problem. I requery the main form just before the
popup closes. Of course the recordset goes back to the first record. I want
the user to stay with the record they were popping up from. I have seen the
other posting on this topic from 7/11/2006. I tried these solutions to no
avail. Here is my code for the button that saves the file name and closes
the popup:

Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Me![txtImagePath] = Me![imgTheImage].Picture
If Validate Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Echo False
Forms("frmStudentEnrollment").Form.Requery
DoCmd.Echo True
DoCmd.GoToRecord acDataForm, "Student Enrollment Upgrade",
[Student#] =" & [Forms]![frmPhotoEntry]![Student#]
DoCmd.Close acForm, Me.Name
End If
Exit_cmdSave_Click:
On Error Resume Next
Exit Sub
Err_cmdSave_Click:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
cmdSave_Click", vbExclamation, "Castle Admin"
Resume Exit_cmdSave_Click
End Sub
 
M

mscertified

Try something like this:

Private Sub Form_Open(Cancel As Integer)
Me.CurRec = vbNullString 'Initialize record position
End Sub

Private Sub Form_GotFocus()
' Restore record position
On Error Resume Next
If Nz(Me.CurRec, vbNullString) <> vbNullString Then
DoCmd.GoToRecord , , acGoTo, Me.CurRec
End If
End Sub

Private Sub Form_LostFocus()
' Save record position
Me.CurRec = Me.CurrentRecord
End Sub
 
L

legere864

That'll do it. Thanks a lot.

mscertified said:
Try something like this:

Private Sub Form_Open(Cancel As Integer)
Me.CurRec = vbNullString 'Initialize record position
End Sub

Private Sub Form_GotFocus()
' Restore record position
On Error Resume Next
If Nz(Me.CurRec, vbNullString) <> vbNullString Then
DoCmd.GoToRecord , , acGoTo, Me.CurRec
End If
End Sub

Private Sub Form_LostFocus()
' Save record position
Me.CurRec = Me.CurrentRecord
End Sub


legere864 said:
I have a main form . . . frmStudentEnrollment

I have a pop-up form . . . frmPhotoEntry

When the user wants to add a photograph to the main form, they click on a
button that opens the popup. When the popup opens the Win Open/Save window
opens to allow the user to select the photo. When the user has selected the
photo, they click a button to close the popup and save the file path to the
recordset. Here's the problem. I requery the main form just before the
popup closes. Of course the recordset goes back to the first record. I want
the user to stay with the record they were popping up from. I have seen the
other posting on this topic from 7/11/2006. I tried these solutions to no
avail. Here is my code for the button that saves the file name and closes
the popup:

Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Me![txtImagePath] = Me![imgTheImage].Picture
If Validate Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Echo False
Forms("frmStudentEnrollment").Form.Requery
DoCmd.Echo True
DoCmd.GoToRecord acDataForm, "Student Enrollment Upgrade",
[Student#] =" & [Forms]![frmPhotoEntry]![Student#]
DoCmd.Close acForm, Me.Name
End If
Exit_cmdSave_Click:
On Error Resume Next
Exit Sub
Err_cmdSave_Click:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
cmdSave_Click", vbExclamation, "Castle Admin"
Resume Exit_cmdSave_Click
End Sub
 

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

Add New Record for Combo Box 5
error 2499 9
Error Code 2046 1
Save Image 0
REquery Subform 1
Table Update ODBC 2
Subform Requery Criteria 1
To Requery or Repaint? 3

Top