Error 3159 - Not a valid bookmark

B

Binta

On a a data entry form for "SerialNo", I am checking to
see if the text entered already exists, if it does, the
user is notified and the record is displayed using a
bookmark property (OnExit event) on the Serial number.
The code works fine and displays records for the firt 200
records i.e. chose any serial number from the first 200
record, and anything after 200 i.e. records # 201 gives
me error # 3159 - "Run time Error, Not a valid
bookmark". Can someone explain and is there a different
way of displaying the record. I can post the code too if
needed. Thanks in advance for any help
 
T

Tim Ferguson

The code works fine and displays records for the firt 200
records i.e. chose any serial number from the first 200
record, and anything after 200 i.e. records # 201 gives
me error # 3159 - "Run time Error, Not a valid
bookmark". Can someone explain

Not without seeing the code: can you post the relevant bits and note
exactly where the error occurs?

Tim F
 
B

Binta Patel

Here's the Code
Option Compare Database
Dim VarBookmark


Public Function CheckSerialDups()

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


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

If objrs1.RecordCount <> 0 Then

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

VarBookmark = objrs1.Bookmark

End If

If Not IsNull(VarBookmark) Then
DoCmd.CancelEvent
SendKeys "{ESC 2}", 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

Public Function GoToBookMarkRecord()


If Not IsNull(VarBookmark) And Len(VarBookmark) <> 0
Then
DoCmd.CancelEvent
Screen.ActiveForm.Bookmark = Found
VarBookmark = Null
End If

End Function
 
B

Binta

By the way I forgot to mention that the error occurs in
the Public Function GoToBookMarkRecord at the following
line (screen.activeform.bookmark = found).

-----Original Message-----
Here's the Code
Option Compare Database
Dim VarBookmark


Public Function CheckSerialDups()

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


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

If objrs1.RecordCount <> 0 Then

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

VarBookmark = objrs1.Bookmark

End If

If Not IsNull(VarBookmark) Then
DoCmd.CancelEvent
SendKeys "{ESC 2}", 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

Public Function GoToBookMarkRecord()


If Not IsNull(VarBookmark) And Len(VarBookmark) <> 0
Then
DoCmd.CancelEvent
Screen.ActiveForm.Bookmark = Found
VarBookmark = Null
End If

End Function

-----Original Message-----


Not without seeing the code: can you post the relevant bits and note
exactly where the error occurs?

Tim F

.
.
 
T

Tim Ferguson

By the way I forgot to mention that the error occurs in
the Public Function GoToBookMarkRecord at the following
line (screen.activeform.bookmark = found).

You haven't said what the error is, but I cannot find a reference to the
variable Found anywhere. I can't really see how this code ever ran right...
it's a good idea always to use Option Explicit because it will catch this
type of error.

A few other points:

This seems a very long way to go about things. Have you tried doing a
simple

DCount("*", "tblGeneralInfo", "Serial = """ & txtSerial & """")

which will return 0 if there is no such value, or >0 if there is? You can
then do a simple If phrase, one side doing nothing and the other side
probably using a DoCmd.GoToRecord method to replace the form.

The use of SendKeys is really, really, really, really, really bad. There is
a DoCmd.RunCommand option to undo changes to the current record.

Global variable are sometimes neccessary, but definitely not here. Just
include the bookmark value (by the way, it's a String value) as a parameter
to the SetFormToBookmark sub. By the way, there is no apparent reason for
this to be a Function, since it doesn't return anything.

Finally: COMMENT YOUR CODE!! You will look at this in three months time in
a daze of wonderment because it will mean nothing to you. A rough target to
aim for as a beginner would be 2:1 -- that's lines of comment to lines of
code. When you get better it goes UP! It's easy to write WORN code, but
it's not clever (write once, read never).

Hope that helps a bit


Tim F
 

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