Search Records--Bookmarks

B

BP

The following code used to work, but has stopped working
all of a sudden and have no clue why, comes up with a
message saying that "Bookmark not found". When the end
user
enters a value in the textbox, checks to see if the PK
exist in the table, if it does, the record is brought up
on the form so the user can see and make changes
according, if the PK does not exist, the record is
entered and saved in the table. When the code was
working, I only had about 100 records, now the number of
records have increased to 1000. Following is the code
that I am using: Found is a variable that stores the
bookmark and is a global variable. When debugging the
found has a value in both the functions.

'USING THIS ON THE BEFORE UPDATE OF TEXTBOX1
Public Function SerialUpdate()

Dim Objrs As ADODB.Recordset
Dim objrs1 As ADODB.Recordset
Dim frm As Form_frmGeneralInfo_New
Dim Serial As ADODB.Field
Dim Serial1 As ADODB.Field
Dim txtSerial As TextBox
Dim txt As String
Dim a

Set objrs1 = New ADODB.Recordset
objrs1.Open "tblGeneralInfo", CurrentProject.Connection,
adOpenKeyset, adLockOptimistic

Set Serial1 = objrs1!SerialNo
Set frm = Forms![frmgeneralinfo_new]
Set txtSerial = frm.SerialNo
txt = txtSerial.Value
Debug.Print "Txt = "; txt


If objrs1.RecordCount <> 0 Then

'MsgBox "The number of records in the current table
are: " & objrs1.RecordCount
objrs1.MoveFirst

Do While Not objrs1.EOF

If (Serial1 = txtSerial.Value) Then

MsgBox "The serial Number you have entered
already exists in the database", vbOKOnly

If Serial1 = txtSerial Then
'MsgBox "TblGeneral", vbOKOnly
Found = objrs1.Bookmark

'MsgBox "Found in before update is: " &
Found
'MsgBox "Found is : " & Found
End If

If Not IsNull(Found) Then
DoCmd.CancelEvent
SendKeys "{ESC 2}{TAB}", False
Exit Function
End If
Else
objrs1.MoveNext
End If

Loop

Else
' MsgBox "There are currently no existing records in
the table", vbOKOnly
'do nothing, do not need to compare because there are
no existing records.
End If


End Function

'USING THIS ON EXIT of the same textbox1
Public Function Find_OnExit1()


Dim frm1 As Form_frmGeneralInfo_New
Set frm1 = Forms![frmgeneralinfo_new]
If Not IsNull(Found) And Len(Found) <> 0 Then
DoCmd.CancelEvent
MsgBox "Found is : " & Found
Screen.ActiveForm.Bookmark = Found
Found = Null
End If

End Function
 

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