B
BruceM
In something such as a WHERE condtion for opening a form, if the matching
field (EmployeeID in this case) is a text field, the WHERE condtion may be
something like:
Dim strWhere as string
strWhere = "EmployeeID = " " " & Me.EmployeeID & " " " "
DoCmd.OpenForm "frmMain", , , strWhere
However, the strWhere line could also be:
strWhere = "EmployeeID = ' " & Me.EmployeeID & " ' "
As I understand, the first would be the choice if EmployeeID could contain
an apostrophe. The second would be the choice if there could be a double
quote in EmployeeID. Other than these circumstances, is there a reason to
prefer one approach over the other, or limitations in either case?
Also, in the unlikely event that the selected field could contain both
apostrophes and double quotes, I think the approach is to double the single
quotes:
strWhere = "EmployeeID = ' ' " & Me.EmployeeID & " ' ' "
or to replace each single quote in the above with a pair of double quotes:
strWhere = "EmployeeID = " " " " " & Me.EmployeeID & " " " " " "
Again, is there a place for either of these approaches other than to guard
against text that could contain both apostrophes and single quotes?
I realize that EmployeeID is not likely to contain either single or double
quotes, and almost certainly not both, but I can imagine fields where the
conditions could apply. The question is general, and not about a particular
field in an actual database.
field (EmployeeID in this case) is a text field, the WHERE condtion may be
something like:
Dim strWhere as string
strWhere = "EmployeeID = " " " & Me.EmployeeID & " " " "
DoCmd.OpenForm "frmMain", , , strWhere
However, the strWhere line could also be:
strWhere = "EmployeeID = ' " & Me.EmployeeID & " ' "
As I understand, the first would be the choice if EmployeeID could contain
an apostrophe. The second would be the choice if there could be a double
quote in EmployeeID. Other than these circumstances, is there a reason to
prefer one approach over the other, or limitations in either case?
Also, in the unlikely event that the selected field could contain both
apostrophes and double quotes, I think the approach is to double the single
quotes:
strWhere = "EmployeeID = ' ' " & Me.EmployeeID & " ' ' "
or to replace each single quote in the above with a pair of double quotes:
strWhere = "EmployeeID = " " " " " & Me.EmployeeID & " " " " " "
Again, is there a place for either of these approaches other than to guard
against text that could contain both apostrophes and single quotes?
I realize that EmployeeID is not likely to contain either single or double
quotes, and almost certainly not both, but I can imagine fields where the
conditions could apply. The question is general, and not about a particular
field in an actual database.