Indeed, the delimiter for the string is a double quote, so VBA assumes you
said:
DoCmd.RunSQL "INSERT INTO tblPermSrvcsIgnore ( Type, Server, [Service
Name] )
SELECT [FORMS]![frmAddPermNoMon]![fldSelShutType] AS Type,
IIf([FORMS]![frmAddPermNoMon]![Frame7]=2,"
given that the string ends as soon as it sees a second ". You can try:
DoCmd.RunSQL "INSERT INTO tblPermSrvcsIgnore ( Type, Server, [Service
Name] )
SELECT [FORMS]![frmAddPermNoMon]![fldSelShutType] AS Type,
IIf([FORMS]![frmAddPermNoMon]![Frame7]=2,""ALL"",[FORMS]![frmAddPermNoMon]![fldSelServer])
AS Server, [FORMS]![frmAddPermNoMon]![fldSelSevice] AS [Service Name];"
since 'doubling' the " indicates, in VBA, that you don't mean to stop the
string at that point.
DoCmd.RunSQL "INSERT INTO tblPermSrvcsIgnore ( Type, Server, [Service
Name] )
SELECT [FORMS]![frmAddPermNoMon]![fldSelShutType] AS Type,
IIf([FORMS]![frmAddPermNoMon]![Frame7]=2,'ALL',[FORMS]![frmAddPermNoMon]![fldSelServer])
AS Server, [FORMS]![frmAddPermNoMon]![fldSelSevice] AS [Service Name];"
would also do, since ' are an alternative delimiter for string.
Vanderghast, Access MVP
GLT said:
Hi Vandeghast,
Thanks for your reply - I have constructed the following SQL in the
Q.Design
Grid and it worked OK, however when converted that into the DoCmd.RunSQL
statement, it errors at the "ALL" point, with a syntax error.
Can anyone advise why and what I need to do to fix it?
Cheers,
GLT.
DoCmd.RunSQL "INSERT INTO tblPermSrvcsIgnore ( Type, Server, [Service
Name] )
SELECT [FORMS]![frmAddPermNoMon]![fldSelShutType] AS Type,
IIf([FORMS]![frmAddPermNoMon]![Frame7]=2,"ALL",[FORMS]![frmAddPermNoMon]![fldSelServer])
AS Server, [FORMS]![frmAddPermNoMon]![fldSelSevice] AS [Service Name];"
vanderghast said:
DoCmd.RunSQL "INSERT INTO tableName(server, type, error) VALUES(
FORMS!formNameHere!server, FORMS!formNameHere!type,
FORMS!formNameHere!error)"
would do in a simpler case. In your case, the
FORMS!formNameHere!server
has to be replace with an iif statement (for which I have some problem to
follow your specs.)
Using DoCmd allows to use FORMS!formName!ControlName WITHOUT having to
use delimiter (for strings and dates), neither to check if that delimiter
is
already present in the value. In other words, it is simpler.
Vanderghast, Access MVP
Hi,
I have three feilds: SERVER, TYPE, ERROR
I would like to simply add a new record (three feilds mentioned above)
to
a
table using VBA (when a user clicks a button), however my form also
contains
an option group, and if the first option button is selected then SERVER
=
ALL, if the second option button is selected, then SERVER = servname.
Can anyone advise the SQL statement I need to use?
Any help is always greatly appreciated...
Cheers,
GLT.