> That SQL assumes that all five fields are numeric. I'm guessing that two of
> your fields are actually text.
>
> If the text value will never have an apostrophe in it, you can use
>
> & "MyField2 = '" & MyControl2.Value & "', " _
>
> Exagerated for clarity, that's
>
> & "MyField2 = ' " & MyControl2.Value & " ', " _
>
> If the text value may have an apostrophe in it, but will never have double
> quotes in it, you can use
>
> & "MyField2 = """ & MyControl2.Value & """, " _
>
> That's three double quotes in a row before and after.
>
> If there's a chance that the text may have both apostrophes and double
> quotes in it, try
>
> & "MyField2 = '" & Replace(MyControl2.Value, "'", "''") & "', " _
>
> Again exagerated for clarity, that's
>
> & "MyField2 = ' " & Replace(MyControl2.Value, " ' ", " ' ' ") & " ', " _
>
> Incidentally, I just noticed an error in what I posted earlier. There's an
> extra comma there. It should be:
>
> strSql = "UPDATE tblMyTable " _
> & "SET MyField1 = " & MyControl1.Value & ", " _
> & "MyField2 = " & MyControl2.Value & ", " _
> & "MyField3 = " & MyControl3.Value & ", " _
> & "MyField4 = " & MyControl4.Value & " " _
> & "WHERE MyField5= " & MyControl5.Value
>
> If after making all those changes you still have problems, put a
>
> Debug.Print strSQL
>
> after your assignment statement. After the code runs, go to the Immediate
> window (Ctrl-G) and check what's actually in the statement you're trying to
> run.
>
> --
> Doug Steele, Microsoft Access MVP
>
http://I.Am/DougSteele> (no private e-mails, please)
>
>
> "Walter" <Walter[ at ]discussions.microsoft.com> wrote in message
> news:2F527E1F-BF52-41AB-9FE0-72BE331AB630[ at ]microsoft.com...
> > Thanks! That worked but now I'm getting a "Too few parameters. Expected 2
> > "
> > error.
> > --
> > Thanks for your help!
> > Walter
> >
> >
> > "Douglas J. Steele" wrote:
> >
> >> strSql = "UPDATE tblMyTable " _
> >> & "SET MyField1 = " & MyControl1.Value & ", " _
> >> & "MyField2 = " & MyControl2.Value & ", " _
> >> & "MyField3 = " & MyControl3.Value & ", " _
> >> & "MyField4 = " & MyControl4.Value & ", " _
> >> & "WHERE ((MyField5)= " & MyControl5.Value & "));"
> >>
> >> although all you really need is
> >>
> >> strSql = "UPDATE tblMyTable " _
> >> & "SET MyField1 = " & MyControl1.Value & ", " _
> >> & "MyField2 = " & MyControl2.Value & ", " _
> >> & "MyField3 = " & MyControl3.Value & ", " _
> >> & "MyField4 = " & MyControl4.Value & ", " _
> >> & "WHERE MyField5= " & MyControl5.Value
> >>
> >>
> >> --
> >> Doug Steele, Microsoft Access MVP
> >>
http://I.Am/DougSteele> >> (no e-mails, please!)
> >>
> >>
> >> "Walter" <Walter[ at ]discussions.microsoft.com> wrote in message
> >> news:BBF159F5-7BC7-4566-A334-BCC0BE35B5E2[ at ]microsoft.com...
> >> >I removed the variables and now I'm getting "expected end of statement
> >> > error". How is the proper way to use the quotes?
> >> >
> >> >
> >> > strSql = "UPDATE tblMyTable " _
> >> > & "SET MyField1 = " & MyControl1.Value," _
> >> > & "MyField2 = " & MyControl2.Value" _
> >> > & "MyField3 = " & MyControl3.Value" _
> >> > & "MyField4 = " MyControl4.Value" _
> >> > & "WHERE ((MyField5)= " & MyControl5.Value));"
> >> > --
> >> > Thanks for your help!
> >> > Walter
> >> >
> >> >
> >> > "Stefan Hoffmann" wrote:
> >> >
> >> >> hi Walter,
> >> >>
> >> >> Walter wrote:
> >> >> > Dim strSql As String
> >> >> > Dim varLO, varLL, varLS, varLTD, varTID As Variant
> >> >> In VBA each variable in such a list without an explicit As Type is
> >> >> declared automatically as Variant. E.g.
> >> >>
> >> >> Dim a, b, c As Long
> >> >>
> >> >> declares a and b as Variant and c as Long.
> >> >>
> >> >>
> >> >> > Set varLO = MyControl1
> >> >> > Set varLL = MyControl2
> >> >> > Set varLS = MyControl3
> >> >> > Set varLTD = MyControl4
> >> >> > Set varTID = MyControl5
> >> >> This is normally not necessary.
> >> >>
> >> >> > Set strSql = "UPDATE tblMyTable " _
> >> >> > & "SET MyField1 = varLO, " _
> >> >> > & "MyField2 = varLL " _
> >> >> > & "MyField3 = varLS " _
> >> >> > & "MyField4 = varLTD " & _
> >> >> > "WHERE ((MyField5)= varTID));"
> >> >> A
> >> >>
> >> >> MsgBox strSQL
> >> >>
> >> >> will show you your error. Use
> >> >>
> >> >> " field = " & MyControl1.Value
> >> >>
> >> >> instead.
> >> >>
> >> >>
> >> >>
> >> >> mfG
> >> >> --> stefan <--
> >> >>
> >>
> >>
> >>
>
>
>