Re: SQL String variable within another String Variable

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Steve S" <SteveS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
<8994D928-0E32-43C2-90D1-6E9C15D2F6A8@xxxxxxxxxxxxx>:
How do I code the following

strInput = "a test"
MsgBox (strInput)
strSQL = "INSERT INTO Comments (Comment) SELECT " & strInput & "as
X;" MsgBox (strSQL)
DoCmd.RunSQL strSQL

so the variable - strInput - is resolved to produce this SQL
statement:

INSERT INTO Comments (Comment) SELECT " Steve " as X;

the last line works fine when I hard code the text I want. I just
can't get the variable tobe resolved correctly.

Steve

Text will need tex delimiters (single quotes), try

strSQL = "INSERT INTO Comments (Comment) Values ('" & _
strInput & "')"

If there's a possibility that the text could contain single quotes, or
other special characters, you might try "doublequoting"

strSQL = "INSERT INTO Comments (Comment) Values (""" & _
strInput & """)"

--
Roy-Vidar


.



Relevant Pages

  • Re: InputBox Werte abfangen
    ... ElseIf IsNumeric= False Then ... MsgBox "Bitte geben Sie eine Zahl ein.", ... DATENBANK.Cells.Value = strInput ...
    (microsoft.public.de.excel)
  • InputBox Werte abfangen
    ... Hier mal der auszug des Code der InputBox: ... MsgBox "Bitte geben Sie eine Zahl ein.", ... DATENBANK.Cells.Value = strInput ...
    (microsoft.public.de.excel)
  • Re: Using MsgBox or InputBox
    ... Dim strInput As String ... MsgBox "I said a single letter!" ... I want to use a MsgBox or InputBox, rather than a form, to capture a single ...
    (microsoft.public.access.formscoding)
  • Fehler gefunden
    ... Hier mal der auszug des Code der InputBox: ... MsgBox "Bitte geben Sie eine Zahl ein.", ... DATENBANK.Cells.Value = strInput ...
    (microsoft.public.de.excel)