473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Combobox lookup function gives syntax error

Hello all,
I have made a form containing a combox which must look up values (names) in
a table. It works fine until the moment I try to put in a name containg an
apostrophe. (e.g. d'Haen). At this moment I receive an errormsg (syntax
error). After closing the msg Access freezes.
Can anybody tell me if there is a solution for this problem? I included the
code below.
Any help very much appreciated!

Ronny Sigo

Private Sub Combo39_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Achternaam] = '" & Me![Combo39] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
Nov 13 '05 #1
1 1908
Ronny Sigo wrote:
Hello all,
I have made a form containing a combox which must look up values (names) in
a table. It works fine until the moment I try to put in a name containg an
apostrophe. (e.g. d'Haen). At this moment I receive an errormsg (syntax
error). After closing the msg Access freezes.
Can anybody tell me if there is a solution for this problem? I included the
code below.
Any help very much appreciated!

Ronny Sigo

Private Sub Combo39_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Achternaam] = '" & Me![Combo39] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub


rs.FindFirst "[Achternaam] = '" & Replace(Me![Combo39],"'","''") & "'"

A few code tips for you:
* Naming conventions help in code, e.g. call your combo box "cboAchternaam".
* Always close recordsets when your finished with them and set the
object variable to Nothing afterwards. Don't let it to VB/VBA to do it
for you, that doesn't always work. Being explicit does.
* Your use of .FindFirst suggest DAO, if that's the case then check for
rs.NoMatch, your code looks like a mismatch of DAO and ADO
* Declare variables explicitly, As Recordset rather than As Object, this
makes things more clear in code.

Using the above, when you go back to this code a year later you'll
instantly understand what's going on.
--
Error reading sig - A)bort R)etry I)nfluence with large hammer
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: John Collyer | last post by:
Hi, In assembly language you can use a lookup table to call functions. 1. Lookup function address in table 2. Call the function Like: CALL FUNCTION
2
by: DBQueen | last post by:
Hi - In my A2K database, I have a form with 2 Unbound Comboboxes, both of which open up forms to a particular record. One of these comboboxes works perfectly. For some reason the 2nd one WILL...
5
by: jaYPee | last post by:
i have successfully added a combobox to my datagrid by setting their datasource from one of my table. here's my code... Dim grdColStyle6 As New DataGridComboBoxColumn() With grdColStyle6...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
10
by: ZaphodBBB | last post by:
HI I have a form with 2 comboBoxes. The first comboBox gives me a list of customers to select from. I would like to have the second comboBox populated with the names of Departments. I only want...
13
by: paul.joseph.davis | last post by:
Hi, I've just had my first encounter with two-phase lookup and I'm scratching my head a bit. The idea behind two phase look up is pretty easy to understand, but I have a case that fails to...
14
by: Mark | last post by:
I have a table with a field that uses a combobox to populate values. The Lookup tab within table design mode is the following: Display Control Combo Box Row Source Type ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.