I am trying to insert a record into the LogicalServer table with an INSERT INTO query from VBA. I get a "Syntax error in INSERT INTO statement" when I use DoCmd.RunSQL sqlAppend statement.
I set up the variable I use for the VALUES portion of the query as follows:
Code:
SNm = Me.txtServerNm
For Each varItm In lstIP.ItemsSelected
vIP = Me.lstIP.Column(0, varItm)
Next varItm
CD = Me.txtComDate
For Each varItm In lstServerType.ItemsSelected
vType = Me.lstServerType.Column(0, varItm)
Next varItm
If (Me.txtDecommDate = "") Then
Ddaate = Empty
Else
Ddate = Me.txtDecommDate
End If
Stat = Me.txtStatus
For Each varItm In lstSvrTypeId.ItemsSelected
PhysS = Me.lstSvrTypeId.Column(0, varItm)
Next varItm
My sqlAppend is
Code:
sqlAppend = "INSERT INTO LogicalServer([Name], [IPID], [CommissionDate], [LogicalSerTypeID], [DecommissionDate], [Sttus], [Physical]" _
& " VALUES (" & SNm & ", '" & vIP & ", '" & CD & ", '" & vType & ", '" & Ddate & ", '" & Stat & ", '" & PhysS & "');"
My table has the following fields:
Field Name Data Type
LogicalServerID Number This number is assigned automatically upon saving the record. It is also a GUID as are IPID and LogicalServerTypeID
Name Short Text
IPID Number
CommissionDate Date/Time
LogicalServerTypeID Number
DecommissionDate Date/Time
Status Short Text
Physical Yes/No
the DeBug>print sqlAppend shows the following:
Code:
INSERT INTO LogicalServer([Name], [IPID], [CommissionDate], [LogicalSerTypeID], [DecommissionDate], [Sttus], [Physical] VALUES (AAAA-JackTest, '{72FE854E-5056-9F6E-4C35-F6A172A91CA9}, '3/21/2019, '{A331FB98-E7FE-E555-74FA-AC3CD4221013}, '12:00:00 AM, 'Active, 'False');
All the VALUES are correct.
If I include the LogicalServerID field in the query I still get an error as this Value would be empty since it is not assigned until the record is saved.
Can anyone show me what is wrong?