472,983 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Syntax error 3075 when typing name with apostrophe in form

1
I am using this vba code to prevent double entry:
Expand|Select|Wrap|Line Numbers
  1. Private Sub BusinessName_AfterUpdate()
  2.   Dim NewBusinessName As String
  3.   Dim stlinkcriteria As String
  4.  
  5.   NewBusinessName = Me.BusinessName.Value
  6.   stlinkcriteria = "[BusinessName] = " & "'" & NewBusinessName & "'"
  7.   If Me.BusinessName = DLookup("[BusinessName]", "Sheet1", stlinkcriteria) Then
  8.   MsgBox "" & NewBusinessName & " is already in the Database." _
  9. & vbCr & vbCr & "Data Entry Denied!!!", vbInformation, "DUPLICATE ENTRY"
  10.   Me.Undo 'undo the process and clear all fields
The code works well to prevent double entry, unfortunately, if the name I typed includes an APOSTROPHE (ex. John's Cafe), syntax error 3075 appears.
Do you have any suggestions to correct the error?
May 7 '22 #1

✓ answered by NeoPa

Hi there, and welcome to Bytes.com.

Yes indeed. Interesting question :-)

This occurs because you're using the correct quote character for SQL strings. To avoid this being a problem you should always pass your string parameters - at least those that could ever contain such characters - via a filter function that doubles them up for you. For more on this see Quotes (') and Double-Quotes (") - Where and When to use them.

An example of such a function procedure is (from SQL Injection Attack) :
Expand|Select|Wrap|Line Numbers
  1. Public Function SafeSQL(strArg As String) As String
  2.     SafeSQL = Replace(strArg, "'", "''")
  3. End Function
Your line #5 would then be :
Expand|Select|Wrap|Line Numbers
  1. NewBusinessName = SafeSQL(Me.BusinessName.Value)
Note that, in most cases where no quotes are contained within the string passed, the value returned will be exactly the same as the original value. Only strings with embedded quotes will ever be changed to ensure they work correctly within SQL.

4 20236
NeoPa
32,548 Expert Mod 16PB
Hi there, and welcome to Bytes.com.

Yes indeed. Interesting question :-)

This occurs because you're using the correct quote character for SQL strings. To avoid this being a problem you should always pass your string parameters - at least those that could ever contain such characters - via a filter function that doubles them up for you. For more on this see Quotes (') and Double-Quotes (") - Where and When to use them.

An example of such a function procedure is (from SQL Injection Attack) :
Expand|Select|Wrap|Line Numbers
  1. Public Function SafeSQL(strArg As String) As String
  2.     SafeSQL = Replace(strArg, "'", "''")
  3. End Function
Your line #5 would then be :
Expand|Select|Wrap|Line Numbers
  1. NewBusinessName = SafeSQL(Me.BusinessName.Value)
Note that, in most cases where no quotes are contained within the string passed, the value returned will be exactly the same as the original value. Only strings with embedded quotes will ever be changed to ensure they work correctly within SQL.
May 7 '22 #2
NeoPa
32,548 Expert Mod 16PB
By the way, correct quotes often fall foul of this with names, but the incorrect ones (") - also allowed in Access & Jet/ACE - have a similar problem when dealing with measurements in inches (") or even seconds (") when dealing with parts of a degree as well as of an hour ;-) Thus it still makes sense to use the correct ones and just ensure you protect your code using this procedure.
May 7 '22 #3
NeoPa
32,548 Expert Mod 16PB
Before I leave you I must just point out that, while it makes sense to catch such problems before trying to save the data, and thus end up with your user being subjected to a basic Access error message, it is also advisable to configure the underlying table field not to accept duplicates by setting the Indexed property to Yes (No duplicates). This will create an index on that field and disallow entry of any duplicate values.
May 7 '22 #4
jameswalter
4 Nibble
"Runtime Error 3075: Syntax Error (missing operator) in query expression ID () and Link LIKE 'SET'"This error occurs when exporting a row format to a . tdb file.

This may help,
James
Oct 28 '22 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jozef | last post by:
Hello, I'm installing a package created with Office XP developers edition Packaging Wizard. I get an "Error 3075" Cannot I've looked at the Microsoft Website and this seems to be an Access 97...
0
by: j.rogel | last post by:
Hello everyone! I am new to this sort of postings so I'm not even sure if this is the correct place to start. Anyway, I would realy appreciate any help. I have a some VBA code that works quite...
3
by: injanib via AccessMonster.com | last post by:
Hello Access Monsters, I have a table with three columns. "CostCenter", "ProjectNumber", "GLCode" On my form I have three texboxes, "txtCostCenter", "txtProjectNumber" and "txtGLCode". the...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
2
by: GLEberts | last post by:
I can not seem to get rid of this syntax error - hope someone can help out. the error I am getting is: Run time Error 3075 Syntax error missing operator in query expression =name I have...
1
by: inbarik | last post by:
Hi, i'm getting syntax error message for this button that tries to get name (of building) with apostrophe. Any idea how to solve this? Note that i must use name with apostrophe e.g. O'neal: ...
2
by: aldwin aldwin | last post by:
Any help what I miss in this code. It shows an error if the value of MeCustName has apostrophe ex: MeCustName = wheel's weight ,it shows an error 3075.Thnx... DoCmd.RunSQL "INSERT INTO...
2
LeighW
by: LeighW | last post by:
Hi all, I have a form, Form 1 with primary key PK_ID I have a second form, Form 2 with foreign key FK_ID I link through to Form 2 using the field PK_ID. It is also possible to open Form 2...
1
by: mknewnham | last post by:
Hello! New to the PHP/coding world so hoping to get some help :) I created a contact form on Adobe Muse and created a PHP file. I found it on a blog and copied it from there (plus changing...
1
by: lmedina3 | last post by:
$paypal_item = $sitename." Service Monthly Subscription"; $paypal_item_number = $sitename; $mainipn = $siteurl."/ipn.php"; $paypal_ipn = $siteurl."/site_ipn.php"; $paypal_cancel_return =...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.