G
gsnidow via AccessMonster.com
Greetings all. I have a main form/sub form set up, where the subform
contains possibly hundreds of records, depending on filtering. On the
subform, there is a button to open a popup to add a note. After the note is
saved, I need to requery the subform to display the note. I am trying to use
a bookmark, but it only works sometimes. If I add a note to a record that
already has a note, the bookmark works. However, if I add a note to a record
that does not currently have a note, it does not work, and returns to the
first record upon the requery. Below is the sub, and I can not figure out
why it is only working some of the time. Maybe it is something simple.
Thank you.
Private Sub cmdAddNote_Click()
On Error GoTo Err_cmdAddNote_Click
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim COMP_KEY As String 'this is the primary key of the record set
'Get the key prior to inserting the note
COMP_KEY = Forms!frmZMMR41_ZZMB52_Main!Child1.Form!txtCompKey.Value
strSQL = "INSERT INTO tblstorekeeper_notes(comp_key,note) " & _
"SELECT '" & COMP_KEY & "', '" & Replace(Me.txtAddNote, "'",
"''") & "'"
'Insert the note
DoCmd.RunSQL strSQL
'create the recordset clone
Set rs = Forms!frmZMMR41_ZZMB52_Main!Child1.Form.Recordset.Clone
'Requery the form to display the new note
Forms!frmZMMR41_ZZMB52_Main!Child1.Form.Requery
'Go back to the record
rs.MoveFirst
rs.Find "comp_key = " & COMP_KEY
Forms!frmZMMR41_ZZMB52_Main!Child1.Form.Bookmark = rs.Bookmark
DoCmd.Close acForm, "frmAddNote"
Exit_cmdAddNote_Click:
Exit Sub
Err_cmdAddNote_Click:
MsgBox Err.Description
Resume Exit_cmdAddNote_Click
End Sub
Greg
contains possibly hundreds of records, depending on filtering. On the
subform, there is a button to open a popup to add a note. After the note is
saved, I need to requery the subform to display the note. I am trying to use
a bookmark, but it only works sometimes. If I add a note to a record that
already has a note, the bookmark works. However, if I add a note to a record
that does not currently have a note, it does not work, and returns to the
first record upon the requery. Below is the sub, and I can not figure out
why it is only working some of the time. Maybe it is something simple.
Thank you.
Private Sub cmdAddNote_Click()
On Error GoTo Err_cmdAddNote_Click
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim COMP_KEY As String 'this is the primary key of the record set
'Get the key prior to inserting the note
COMP_KEY = Forms!frmZMMR41_ZZMB52_Main!Child1.Form!txtCompKey.Value
strSQL = "INSERT INTO tblstorekeeper_notes(comp_key,note) " & _
"SELECT '" & COMP_KEY & "', '" & Replace(Me.txtAddNote, "'",
"''") & "'"
'Insert the note
DoCmd.RunSQL strSQL
'create the recordset clone
Set rs = Forms!frmZMMR41_ZZMB52_Main!Child1.Form.Recordset.Clone
'Requery the form to display the new note
Forms!frmZMMR41_ZZMB52_Main!Child1.Form.Requery
'Go back to the record
rs.MoveFirst
rs.Find "comp_key = " & COMP_KEY
Forms!frmZMMR41_ZZMB52_Main!Child1.Form.Bookmark = rs.Bookmark
DoCmd.Close acForm, "frmAddNote"
Exit_cmdAddNote_Click:
Exit Sub
Err_cmdAddNote_Click:
MsgBox Err.Description
Resume Exit_cmdAddNote_Click
End Sub
Greg