Help with bracketing

battenberg

Burning candles both ends
Local time
Today, 19:52
Joined
Sep 25, 2006
Messages
118
Hi

I am using the following code on a DBL click event to move to a new form and open an appropriate record, the problem i am facing is when the company name has an apostraphe in it ie: [two o'clock] the code falls over.
i think this can be solved with bracketing.... can anyone help me with the correct syntax for the bracketing please???


Code:
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmProjects"
    
    stLinkCriteria = "[CompanyName]=" & "'" & Me![CompanyName] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
 
stLinkCriteria = "[CompanyName]=" & Chr(34) & Me![CompanyName] & Chr(34)
 
Once again RG you amaze me with genius!, an obvious solution, but only when your mind can think in this way...

thanks a million...
 
Offcourse now this will fall over if there is a " in the name.

The best way around this is to NOT use the name at all but rather the PK of the table.

Greets

Edit:
It is easier (not better or worse tho) to use Me.CompanyName instead of Me![CompanyName]
 
RuralGuy said:
stLinkCriteria = "[CompanyName]=" & Chr(34) & Me![CompanyName] & Chr(34)

Chr(34) = "

You could alternatively use the following:
stLinkCriteria = "[CompanyName]=""" & Me![CompanyName] & """"

since in program code "" is equal to a displayed "
 

Users who are viewing this thread

Back
Top Bottom