Using Bookmark to display record

K

KLR

I have a main form with 2 subforms set up. They are linked by an
institution name. The user is prompted to choose an institution from a
drop down menu in the header. I have placed the following code behind
the After Update property of the combo box.

Private Sub Institution_AfterUpdate()
'Move to the record selected in the control
Me.RecordsetClone.Findfirst "[Institution] = " & Me![Institution]
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

I get an error message displayed when trying to choose an institution:-

Run time error 3077
Syntax error (missing operator) in expression

Pressing debug highlights the "Me.RecordsetClone" line.

Pressing End will display the information as required.

I don't know what I am doing wrong :(
 
A

Allen Browne

If you backspace the value out of the Institution combo, its value is Null.
Then the line:
"[Institution] = " & Me![Institution]
resolves to just:
"[Institution] = "
which makes no sense to Access.

To avoid the situation, check for Null first.

If Institution is a Text type field (not a Number type field), you need
extra quotes:
"[Institution] = """ & Me![Institution] & """"

If the Institution combo is bound to a field, the attempt to move may fail,
because have changed the existing record (probably not want you wanted.)

If it is not bound to the field, but there is a field by that name in your
form, Access is likely to get confused.

There are other potential problems with that code as well, such as the test
to test for NoMatch after the FindFirst.

For a version of the code that deals with these issues and will work
reliably, see:
Using a Combo Box to Find Records
at:
http://allenbrowne.com/ser-03.html
 

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

Similar Threads

Query creating duplicate record 1
Combo Name with ' 2
Run Time error 3077 3
Clone Code Complication 2
Return to same record after Requery 3
RecordSet.FindFirst 2
Moving a bound form to a record 2
Data from tables 17

Top