473,403 Members | 2,323 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,403 software developers and data experts.

AfterUpdate Event Procedure

418 256MB
My form is called fItems that is based on a table called Items.

A text box named iTitle is added to fItems. To avoid duplication of a title I added the following codes as an After_Update for iTitle. It's working with one problem. If I have an apostrophe in a title I get an error message:
Run Time Error '3075': Syntax error (missing operator) in query expression '[iTitle] = "Who's Coming to Dinner"

Expand|Select|Wrap|Line Numbers
  1. Private Sub iTitle_AfterUpdate()
  2. Dim iTitle As String
  3.     Dim stLinkCriteria As String
  4.     Dim rsc As DAO.Recordset
  5.  
  6.     Set rsc = Me.RecordsetClone
  7.  
  8.     iTitle = Me.iTitle.Value
  9.     stLinkCriteria = "[iTitle]=" & "'" & [iTitle] & "'"
  10.  
  11.     'Check Items table for duplicate iTitle
  12.     If DCount("iTitle", "Items", _
  13.               stLinkCriteria) > 0 Then
  14.  
  15.  
  16.         'Undo duplicate entry
  17.         Me.Undo
  18.         'Message box warning of duplication
  19.         MsgBox "Warning Item Title " _
  20.              & iTitle & " has already been entered." _
  21.              & vbCr & vbCr & "You will now been taken to the record.", _
  22.                vbInformation, "Duplicate Information"
  23.         'Go to record of original Title
  24.         rsc.FindFirst stLinkCriteria
  25.         Me.Bookmark = rsc.Bookmark
  26.     End If
  27.  
  28.     Set rsc = Nothing
  29. End Sub
  30.  
Can someone please help me correct this coding? Many thanks.
Apr 27 '10 #1
5 2223
code green
1,726 Expert 1GB
You either need to use
Expand|Select|Wrap|Line Numbers
  1. Replace(string, search for, replace with
  2.  
Or double up the offending character
Apr 28 '10 #2
MNNovice
418 256MB
Sorry, but I don't understand your suggestions. I am novice at coding. Thanks.
Apr 28 '10 #3
code green
1,726 Expert 1GB
Things like commas, quotes, slashes buried within text can cause problems with many programming languages.
So your problem is not unusual particularly from a form.

It is a good idea to write a form input cleaning function to handle this problem.
This can be modified to suit your needs but at he moment you need
Expand|Select|Wrap|Line Numbers
  1. cleanString = Replace(dirtyString, character,"")
This will remove character from dirtyString
Or the quote can be escaped by adding another quote
Expand|Select|Wrap|Line Numbers
  1. cleanString = Replace(dirtyString, character,"''")
But this is more useful for database insertion
Apr 29 '10 #4
MNNovice
418 256MB
@code green
Code Green,
Thanks for your kind information. While I was waiting for your response, I searched the internet and found this solution to my problem:

Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[iTitle]=" & "'" & Replace(Me![iTitle],"'","''") & "'"
I added this code to replace:
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[iTitle]=" & "'" & [iTitle] & "'" 
This took care of my problem. My question to you:

1. Does this new code have any limitations?
2. How does your code:
Expand|Select|Wrap|Line Numbers
  1. cleanString = Replace(dirtyString, character,"") 
differ from the one I just used?
3. If your code is the best way to take care of any possible dirty string issues, where am I supposed to add this code? Please be specific and tell me where to insert this new code between which lines?

Many thanks. I wait for your response.


My question to you
Apr 29 '10 #5
code green
1,726 Expert 1GB
The two pieces of code clean the input in the same way using Replace().
It is just that the example you found does some additional concatenation.

You need to insert the code just after you read the data.
But I seriously recommend writing a function and calling that, rather then using inline code.
May 4 '10 #6

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

Similar topics

1
by: Chris Thompson | last post by:
I am using Access 97 (if this makes any difference to any answers). On a form I have a combobox and I want it such that when a user selects an item from the list, this executes an 'INSERT INTO'...
3
by: jdph40 | last post by:
In Access 2002, I designed a simple database for our Safety department to enter results of a survey. There are 41 true/false statements. I have a main form called frmSurvey with a subform called...
2
by: jv | last post by:
Hello, I have a Service Cancellation form that contain a CancelDate text box. The text box has an AfterUpdate event that perform a few calculations. This works fine. However, next to the text...
5
by: ewp568 | last post by:
I have a subform that, when updated should place a "Last Updated" time stamp in the record using the following code: Private Sub Form_AfterUpdate() Me! = Now() End Sub However, when I try to...
5
by: EManning | last post by:
I'm developing an unbound form with a series of questions on it. Each question is either a text box or an option group. I have coding in the AfterUpdate event of each control to highlight the...
2
MatthewML
by: MatthewML | last post by:
I am attempting to insert a custom AfterUpdate Event Procedure into a text box on a form that I am designing in MS Access 2000. This text box contains the e-mail address of the referenced contact,...
4
by: bcallnan | last post by:
Hello All- I am trying to reference a subform's afterupdate event that is 3 deep and am having some trouble getting it to work. The control is a combo box and i cannot seem to trigger the...
12
by: Gerhard | last post by:
This is bizarre... Im having problems with the combobox AfterUpdate event: Im running Access 2003. I created an unbound combobox with 3 columns on a form. The Row Source is from a table....
3
mshmyob
by: mshmyob | last post by:
I am scratching my head over this. I have a combo box control where the afterupdate event or even the onchange event keeps runnning twice. Below is some simple code to emulate the problem I am...
1
by: garyb2008 | last post by:
Hi I have a form bound to a stored procedure. I have made it that on changing the value of a list box the form moves forward a record. I have done this using the afterupdate event of the list...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.