Original location: http: //dev.9cbs.net/author/fanpingli/1742be883708457999b0ad569b82c878.html
Function Q (Byval Sqlvariable As Variant) AS String '--------------------------------------- - 'Notes: Useful in Creating Properly Formatted SQL Statements' usage: SQL = "SELECT * from Table where name =" & q (vntname)' ?? version of the version is suitable for access to Access, if other than other? Or? Do you need? Does it? Change '-----------------------------------------
ON Error Goto Ertrapq = Sqlvariable'Format The String Select Case Vartype (Sqlvariable) Case VBNULL, VBEMPTY Q = "Null" Case VBString Q = "'" & Replace (Sqlvariable, "'", "'") & "'" 'date variable Case vbDate' format and enclose in pounds signs for Access Q = " '" & Format $ (SqlVariable, "general date") & "'" 'otherwise treat as numeric Case Else On Error Resume Next Q = CStr (SqlVariable ) If err.number <> 0 THEN Q = SQLVARIABLE END SELECT EXIT FUNCTION
Errtrap: On Error Goto 0nd Function