Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

not a valid bookmark

Status
Not open for further replies.

peljo

Technical User
Mar 3, 2006
91
BG

I have a function that finds a customer.When the customer does not exist, i get the error not a valid bookmark.
Can you help me with my function ? Is there something wrong with it ? Can i improve it and make it more stable ?

Public Function FindCustomer()
Dim f As Form
Set f = Forms!FCustomers
Dim strCustomerID As String
Dim strBookmark As String
strCustomerID = InputBox("Enter customer number ? ")
If strCustomerID = "" Then
Exit Function
End If
f.RecordsetClone.FindFirst "CustomerID = " & strCustomerID
If f.RecordsetClone.NoMatch Then
MsgBox "customer " & strCustomerID & " does not exist!!"
f.Bookmark = strBookmark
Else
f.Bookmark = f.RecordsetClone.Bookmark
End If

End Function
 
First, variables that contain bookmarks need to be Variants ... not strings.

Second, you have not set strBookmark to any value so, when you do this

f.Bookmark = strBookmark

strBookmark is an empty string and is not a valid bookmark.

Why do you need to set the bookmark when you didn't find anything?

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
Public Function FindCustomer()
Dim f As Form
Dim strCustomerID As String
Dim strBookmark As String

Set f = Forms!FCustomers

strCustomerID = InputBox("Enter customer number ? ")

If strCustomerID = "" Then
Exit Function
End If

f.RecordsetClone.FindFirst "CustomerID = " & strCustomerID

If f.RecordsetClone.NoMatch Then
MsgBox "customer " & strCustomerID & " does not exist!!"
Else
f.Bookmark = f.RecordsetClone.Bookmark
End If

End Function


What do you want this to equal "f.Bookmark = strBookmark"??

that's where your error is, remove if record should stay where is
 
How are ya peljo . . .

. . . and this:
Code:
[blue]Public Function FindCustomer()
   Dim f As Form, strCustomerID As String, strBookmark
   
   Set f = Forms!FCustomers
   strCustomerID = InputBox("Enter customer number  ? ")
   
   If strCustomerID <> "" Then
      f.RecordsetClone.FindFirst "CustomerID = " & [purple][b]Val([/b][/purple]strCustomerID[purple][b])[/b][/purple]
      
      If f.RecordsetClone.NoMatch Then
         MsgBox "customer " & strCustomerID & " does not exist!!"
      Else
      f.Bookmark = f.RecordsetClone.Bookmark
      End If
   
   End If

End Function[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top