473,396 Members | 1,766 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,396 software developers and data experts.

3077 error remedied, does not work with index, yes no duplicates

1
I have created a search field on a form that refers to a query. It searches by Organization Name. Some organizations have an apostrophe in the name, and that caused an error No. 3077. This was remedied with the following code:

Expand|Select|Wrap|Line Numbers
  1. Public Function fHandleApostrophe(strPass As String) As String
  2.     Dim strRet As String
  3.  
  4.     strRet = strPass
  5.     If InStr(1, strRet, "'", vbTextCompare) > 0 Then
  6.         strRet = "'" & Replace(strRet, "'", "''", , , vbTextCompare) & "'"
  7.     Else
  8.         strRet = "'" & strRet & "'"
  9.     End If
  10.     fHandleApostrophe = strRet
  11. End Function
Expand|Select|Wrap|Line Numbers
  1. Sub cmbOrgName_AfterUpdate()
  2. ' Find the record that matches the control.
  3. Me.RecordsetClone.FindFirst "[OrganizationName]= " & fHandleApostrophe(Me![cmbOrgName])
  4. Me.Bookmark = Me.RecordsetClone.Bookmark
  5. End Sub
Now I am able to perform the search and have the form autofill after a selection.

My problem is that I then changed gave that field an index of "Yes (No Duplicates)". After I did that, my search still works, UNLESS I SELECT AN ORGANIZATION WITH AN APOSTROPHE in the name. It works if it is not indexed, but not if it is indexed. I need the field to be indexed, no duplicates, but also need the search field to work. Any suggestions?
Nov 23 '11 #1
2 1429
TheSmileyCoder
2,322 Expert Mod 2GB
This is one of those questions where I start out thinking that the original poster is just confused and has messed up something. I thought it would be ridiculous for the index to have any effect on the findfirst method.

However, I was able to recreate the issue you described, and I must admit to being confused myself, and my quick search didn't find any reasons as to why it would be so.

A thing to note, is that when you are doing comparisons with strings, you need to let the SQL engine (in your case probably the native access JET engine) know, that you want to compare a string. So in a normal case, where there would be no apostrophes, you would need to write:
Expand|Select|Wrap|Line Numbers
  1. Me.RecordsetClone.FindFirst "[OrganizationName]= '" & Me![cmbOrgName] & "'"
Note the apostrophe before and after the search word (cmbOrgName).

Back to your problem, Access will in alot of cases be able to switch out a single apostrophe with a double, and thats the case here as well, but it needs to be done a bit differently, since if we simply write the " the VBA engine will interpret it, as being the start or end of a string literal. So we use chr(34) which is the ascii charecter for ".

In the end it looks like this:
Expand|Select|Wrap|Line Numbers
  1. Me.RecordsetClone.FindFirst "[OrganizationName]=" & chr(34) & Me![cmbOrgName] & chr(34)
A short note to add is that if you should have any names with a double apostrophe, you would still get an error 3077, but I find that unlikely.
Nov 23 '11 #2
NeoPa
32,556 Expert Mod 16PB
It sounds like the string is being processed twice for some reason. The doubling up of the quote chars gets it past the first, but when it gets to the second, the pair of quotes has already been converted to a single, which then is treaded as the end of the string (instead of a character in its own right).

Why not try quadrupling them instead in your function (which could be simpler btw) :
Expand|Select|Wrap|Line Numbers
  1. Public Function fHandleApostrophe(strPass As String) As String
  2.     fHandleApostrophe = "'" & Replace(strPass, "'", "''''") & "'"
  3. End Function
There is no need to check the value first as Replace() will leave as is if none is found anyway.

Using double-quotes (") instead of single-quotes (') is unlikely to work if the problem is as I assume. If you do choose to use them doubling them up is generally preferable to the more confusing method of using Chr() calls to build up your strings (Sorry Smiley). It's often suggested as a solution but I fail to see any merit in it whatsoever (over and above other clearer ways of saying the same thing). More on this topic can be found at Quotes (') and Double-Quotes (") - Where and When to use them.
Nov 24 '11 #3

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

Similar topics

1
by: Dynamo | last post by:
Not sure if this is the right group for this question but here goes anyway. Does using index.php instead of index.htm affect the way that your site is crawled by major search engines? Reason I...
6
by: Andy | last post by:
hI, wOULD PLEASE HELP ME. I AM GETTIGN THE REQUEST OBJECT ERROS ASP 0105: 80004005 INDEX OUT OF RANGE ERROR. HERE IS THE SNIPPET OF CODE THAT I AM USING. WHAT IS WRONG HERE? YOU CAN SEE WHAT I AM...
10
by: DataBard007 | last post by:
Hello Access Gurus: I use Win98SE and Access97. I just built a simple Access97 application which holds all contact information for my personal contacts, such as first name, last name, address,...
1
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- ...
4
by: Michael R | last post by:
Or is it not necessary to have that option on the related table field, as the primary table indexed field does that job? And is it a necessity to have the related table field to be indexed if I...
0
by: Xh | last post by:
Hi all, I have successfully installed DB2 Net Search Extender. DB2Ext is up and running, I've run successfully this command: db2text ENABLE DATABASE FOR TEXT CONNECT TO TEST1; but when I...
3
by: DKelley | last post by:
I'm receiving a "severe" error that I can't seem to trap and evaluate in SQL Server 2000 (and no, I can't switch to 2005, this is on our customers' machines). And I've not been able to find info on...
1
AnuSumesh
by: AnuSumesh | last post by:
Hi All, I have installed Local CA (Microsoft) . At the time of installation, it was working fine. Suddenly after 1 week, CA service is stopped and when tried to start the service it displays the...
1
by: ashdaredevil | last post by:
when i am addind a database file to project as data source sql server database file the following error generated error: user does not have permission to perform this action please help me...
3
by: mahmoodn | last post by:
Hi, I have a struct with this definition struct SeverityAction : public Action { uint32_t theSeverity; //***** public: SeverityAction(uint32_t aSeverity); ... };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.