2

I am attempting to create the following SQL INSERT INTO statement, but I am getting a Syntax Error. Any suggestions?:

SQL = "
INSERT INTO AptRent 
    (BuildingID,
     RentAmountID, 
     InitialRentDueDate, 
     TenantID, 
     AptNoID, 
     MoveInDate, 
     MoveOutDate,  
     DateAdded, 
     SecurityAmount, 
     SecurityPaid, 
     NoDaysLate, 
     LateAmount) 
    VALUES
    (" & Me.cbSelectBuildingForRental & "," 
       & Me.cbCreateRentalRentAmount & "," 
       & Me.tbCreateRentalRDD & "," 
       & Me.cbSelectTenantForRental & ", '" 
       & Me.cbSelectAptNoforRental & "' ," 
       & Me.tbCreateRentalMID & "," 
       & Me.tbCreateRentalMOD & "," 
       & Now() & "," 
       & Me.tbSecurityAmnt & "," 
       & Me.ckSecurityPd & "," 
       & Me.tbNoDaysLate & "," 
       & Me.tbLatePmnt & ")"

Table AptRent has the following data types:

BuildingRentID: AutoNumber

BuildingID: Number (Me.cbSelectBuildingForRental)

RentAmountID: Number (Me.cbCreateRentalRentAmount)

InitialRentDueDate: Date/Time (Me.tbCreateRentalRDD)

TenantID: Number (Me.cbSelectTenantForRental)

AptNoID: Text (Me.cbSelectAptNoforRental)

MoveInDate: Date/Time (Me.tbCreateRentalMID)

MoveOutDate: Date/Time (Me.tbCreateRentalMOD)

DateAdded: Date/Time (Now())

SecurityAmount: Currency (Me.tbSecurityAmnt)

SecurityPaid: Yes/No (Me.ckSecurityPd)

NoDaysLate: Number (Me.tbNoDaysLate)

LateAmount: Currency (Me.tbLatePmnt)

1 Answer 1

1

Assuming they're ISO formatted (YYYY-MM-DD HH:NN:SS), you need to add single quotes around your Date/Time values.

...
& "'" & Me.tbCreateRentalMID & "', " 
...

and so on for all of your Date/Time columns.

Sign up to request clarification or add additional context in comments.

3 Comments

Actually, since he's using ms-access. He'll want to use # instead of '.
@DanielCook: I believe single quotes will work when the value is ISO formatted, which I stated in my assumption. Otherwise, you are correct.
I think it depends on what "engine" he's using to run this statement. If it's DAO or ODBC Linked Tables (which is also DAO) then he will need hash signs. I believe ADO also requires hash signs although I'm not perfectly sure on that. In any case, he certainly does need something around the date values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.