Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert statement not working

Status
Not open for further replies.

shaunacol

Programmer
Jan 29, 2001
226
GB

I am using MS access 2010 and would like to append a value into a table, i looked up the format but it does not work


Private Sub Status_AfterUpdate()
If Status = 4 Then
INSERT INTO Tbl_IF(ready)
VALUES (True)
Else If Status = 15 Then
INSERT INTO Tbl_viewing(ready)
VALUES (True)
Else: End If
End Sub

 
You can't mix VBA and SQL code !
Have a look at the DoCmd.RunSQL or CurrentDb.Execute methods.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yr right, i will need to insert the ClientID in there too. It is so that when they choose a status of 'book flight' then the flight table gets a blank field ready for the admin lady and it pops up in her list ready to be booked, hope that makes sense.
 
Hi I am OK now thank you the code below worked. Many thanks for the advice:


Private Sub Status_AfterUpdate()

Dim strSQL as String

If Status = 4 then
strSQL = "INSERT INTO Tbl_IF (ready) VALUES (true);"
Elseif Status = 15 then
strSQL = "INSERT INTO Tbl_viewing (ready) VALUES (true);"
End if

If strSQL <> "" then currentdb.Execute(strSQL)

End Sub
 
shaunacol,
Please consider using TGML to format your messages. They will be much easier to read.
Code:
Private Sub Status_AfterUpdate()

    Dim strSQL as String

    If Status = 4 then
        strSQL = "INSERT INTO Tbl_IF (ready) VALUES (true);"
     Elseif Status = 15 then
        strSQL = "INSERT INTO Tbl_viewing (ready) VALUES (true);"
    End if

    If strSQL <> "" then currentdb.Execute(strSQL)

End Sub

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top