Quaterno
Programmer
- Jan 30, 2009
- 3
I am trying to create a database for my dad's business and I need a button on a form that creates a query from a table of customers with just one record in (the customer that is currently selected on the form). It then needs to check the value of a field called numberofcalls and change the value of datetocall accordingly. The idea of this is that when the customer is called for the first time, the date to call them next is moved forward by two days. Then when they are called the second time, it is moved forward 4 days (end of the week) and then 7 days every time after that (so they are called weekly).
This is the code I have in my VB attached to the button I want to use, in the click event:
Dim SQL As String
SQL = "SELECT tbl_customers.CustID, tbl_customers.Fname, tbl_customers.Sname, tbl_customers.Numberofcalls, tbl_customers.Datetocall " & _
"FROM tbl_customers " & _
"WHERE (((tbl_customers.CustID)=me.[custid]));" & _
"UPDATE tbl_customers SET datetocall = datetocall + 2, numberofcalls = numberofcalls + 1" & _
"WHERE numberofcalls = 0;" & _
"UPDATE tbl_customers SET datetocall = datetocall + 5, numberofcalls = numberofcalls + 1" & _
"WHERE numberofcalls = 1;" & _
"UPDATE tbl_customers SET datetocall = datetocall + 7, numberofcalls = numberofcalls + 1" & _
"WHERE numberofcalls > 1;"
DoCmd.RunSQL SQL
When I run this I get an error: "Characters found after end of SQL statement"
I'm no SQL programmer and I need some help, any help anyone could give would be greatly appreciated.
This is the code I have in my VB attached to the button I want to use, in the click event:
Dim SQL As String
SQL = "SELECT tbl_customers.CustID, tbl_customers.Fname, tbl_customers.Sname, tbl_customers.Numberofcalls, tbl_customers.Datetocall " & _
"FROM tbl_customers " & _
"WHERE (((tbl_customers.CustID)=me.[custid]));" & _
"UPDATE tbl_customers SET datetocall = datetocall + 2, numberofcalls = numberofcalls + 1" & _
"WHERE numberofcalls = 0;" & _
"UPDATE tbl_customers SET datetocall = datetocall + 5, numberofcalls = numberofcalls + 1" & _
"WHERE numberofcalls = 1;" & _
"UPDATE tbl_customers SET datetocall = datetocall + 7, numberofcalls = numberofcalls + 1" & _
"WHERE numberofcalls > 1;"
DoCmd.RunSQL SQL
When I run this I get an error: "Characters found after end of SQL statement"
I'm no SQL programmer and I need some help, any help anyone could give would be greatly appreciated.