Occasional Quotation Marks

Glue

Registered User.
Local time
Today, 05:12
Joined
Jul 11, 2012
Messages
16
Hello All,
I have a Continuous form with a text field named Description that holds data input by users. The information usually contains a size such as 1/4" or 1/2" but won't always have the " which is used to denote Inch. I'm using the following code to automatically copy the last field into the next field so it doesn't have to be retyped on each line.

Const cQuote = """"
Me!Description.DefaultValue = cQuote & Me!Description.Value & cQuote

It is working fine unless the user uses " to denote inches.

Can anyone help me with some code so that this will work regardless of whether the user inputs 1/4" or inputes 1/4 Inch? Is there an if function that would determine if " is a character in the input data?

Thank you in advance
 
In the textboxes AfterUpdate event do a simple for next loop through the length of the text and look for chr(34).

Code:
Private Sub Text7_AfterUpdate()
For lp = 1 To Len(Text7)
    If Mid(Text7, lp, 1) = Chr(34) Then 'do what you wan there
Next lp
End Sub

Or in the Change event ' this removes the "
Code:
Private Sub Text7_Change()
If Right(Text7.Text, 1) = Chr(34) Then
   l = Len(Text7.Text)
    Text7.Text = Left(Text7.Text, l - 1)
    Text7.SelStart = l - 1
End If
End Sub

or you could intercept the keystroke and do something at that time

Code:
If KeyCode = 50 And (Shift And acShiftMask) > 0 Then
    'do your stuff here
End If
 
Last edited:
To use your example, you could use the Replace function to, er, replace the (code for the) double quote in the text with (code for the) 2 double quotes , ie

Me!Description.DefaultValue = cQuote & Replace(Me!Description.Value, Chr(34), Chr(34) & Chr(34), 1, -1) & cQuote

Alternatively, you could dispense with the cQuote constant and just use single quotes instead, ie

Me!Description.DefaultValue = "'" & Me!Description.Value & "'"
 
Thanks to both of you... Got me going in the right direction. Here's what it lead me to which is working great! So thankful there are people out there willing to post responses!!! The last part of the replace code is (" then ' then ' then ")

Private Sub Form_BeforeUpdate(Cancel As Integer)
Const cQuote = """"
Description = Replace(Description, Chr(34), "''")
Me!Description.DefaultValue = cQuote & Me!Description.Value & cQuote
 

Users who are viewing this thread

Back
Top Bottom