Search box in Form not linked to table?

R

RYANneedsHELP

I created a form with a search box but the form does not show a record
exists, even though if I pull up the table it shows there being records.
Interestingly, when i type the names in the form, i can search them; but when
i close out the form and reopen and search for the same record it shows
nothing (even though that record exists in the table).

I have this for my code:

Private Sub SearchLastName_AfterUpdate()

With Me.RecordsetClone
..FindFirst "SSN=" & Me!SearchLastName
If .NoMatch Then
MsgBox "No match was found"
Else
Me.Bookmark = .Bookmark
End If
End With
End Sub
 
A

Allen Browne

Suggestions:

1. Are you sure you are matching the right field?
the code looks like you might be searching for a name in a social securtiy
number field.

2. Do you have the right delimiters?
If SSN is a Text field (not a Number field), you need additional quote
marks:
.FindFirst "SSN=""" & Me!SearchLastName & """"
For an explanation of the quotes, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

3. Is there a reason it might not be found? Examples:
- Form is in Data Entry mode
- Filter is applied
- Form is based on a query that excludes some records

4. Is SearchLastName unbound?
It needs to be.

5. Is the data an exact match?
Could there be something (like a leading space, or accented character) that
is not making the match.

6. Is there a reason the form cannot move to the desired record?
Try explicitly saving:
If Me.Dirty Then RunCommand acCmdSaveRecord
 
R

RYANneedsHELP

Nothing...

When i hit the debugger button, it highlites the "Me.Bookmark" line, is this
something?
 
A

Allen Browne

It may not be the right kind of recordset. Try:

Private Sub SearchLastName_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone

rs.FindFirst "SSN=" & Me!SearchLastName
If rs.NoMatch Then
MsgBox "No match was found"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End Sub

You could also try inserting this in the white space above:
If Not rs.Bookmarkable Then
MsgBox "This is not going to work!"
End If
 

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