Solved

Navigate to a record using a combo box

Posted on 2011-10-01
7
406 Views
Last Modified: 2013-11-05
I have a form which contains a combo box.  When the user selects a record from the combo box I want that record to be displayed on the form.  But I'm getting a type mismatch error.  Here's the code.

    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[PartN] = " & Str(Nz(Me![Combo34], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark

PartN is a text field by the way.  What is wrong with the code?
0
Comment
Question by:SteveL13
  • 3
  • 3
7 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 36896508
You need to use quotes to delimit text:

  Set rs = Me.Recordset.Clone
    rs.FindFirst "[PartN] = " & chr(34) &  & Str(Nz(Me![Combo34], 0)) & chr(34)
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark

0
 
LVL 61

Expert Comment

by:mbizup
ID: 36896528
Chr(34) are double quotes.

Single quotes also work:

Set rs = Me.Recordset.Clone
    rs.FindFirst "[PartN] = '"  & Str(Nz(Me![Combo34], 0)) & "'"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark



But they will cause errors if your data contains single quotes ('), such as in names like O'Brien.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36898267
And I would recommend using the rs.nomatch method to determine whether there was a match.

Set rs = me.recordsetclone
Rs.findfirst "[PartN] = '" & nz(me.combo34,0) & """"
If rs.nomatch = false then me.bookmark = rs.bookmark
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:SteveL13
ID: 36903969
When I copy/paste this code I get red copy on the 2nd line...


  Set rs = Me.Recordset.Clone
    rs.FindFirst "[PartN] = " & chr(34) &  & Str(Nz(Me![Combo34], 0)) & chr(34)
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark

0
 

Author Comment

by:SteveL13
ID: 36903981
Sorry.. I meant type mismatch
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 36904102
Sorry...

Correct it like this:

rs.FindFirst "[PartN] = " & chr(34)  & Str(Nz(Me![Combo34], 0)) & chr(34)

Also, I believe the str() is unneeded:

rs.FindFirst "[PartN] = " & chr(34) &  Nz(Me![Combo34], 0) & chr(34)

Finally, is PartN text or numeric?  The above assume it is text.  If it is numeric, the syntax would be quite different:

rs.FindFirst "[PartN] = " &  Nz(Me![Combo34], 0)
0
 

Author Closing Comment

by:SteveL13
ID: 36932074
That did it.  Thanks.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question