Solved

Navigate to a record using a combo box

Posted on 2011-10-01
7
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 48

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

688 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