I think there is something really obvious I am missing but I can't figure it out - I've been teaching myself vba and I'm still pretty novice.
I am trying to update a table using a sql query in vba and I'd like to update multiple rows at the same time with client IDs that are within some vector of values. My code is below:
' Run a pre-defined insertquery to add a row to the Client table (1 row per client)
DoCmd.RunSQL insertquery
' Find out what the autogenerated clientKey is for this newly entered row in the Client table
Dim newclientKey As Integer
newclientKey = DMax("clientKey", "Client")
' In a separate table (linkClientConsultation) use this newclientKey to replace old clientKey values equal to 36 or 38. These numbers are drawn from commands on the form called Me.clientAkey.Value and Me.clientBkey.Value
updatequery = "UPDATE linkClientConsultation SET clientKey = " & newclientKey & " WHERE clientKey IN (" & Me.clientBkey.Value & "," & Me.clientAkey.Value & ");"
DoCmd.RunSQL updatequery
The Debug.Print version of the query looks like this:
UPDATE linkClientConsultation SET clientKey = 41 WHERE clientKey IN (36,38);
However, while I'd expect this to replace the value of clientKey in the linkClientConsultation where it equals 36 or 38 with 41, it only replaces one of the two values - always the first of the two numbers but not both. Is this a syntax thing? Or a order of operations thing?
Sorry if this is a repeat.
I am trying to update a table using a sql query in vba and I'd like to update multiple rows at the same time with client IDs that are within some vector of values. My code is below:
' Run a pre-defined insertquery to add a row to the Client table (1 row per client)
DoCmd.RunSQL insertquery
' Find out what the autogenerated clientKey is for this newly entered row in the Client table
Dim newclientKey As Integer
newclientKey = DMax("clientKey", "Client")
' In a separate table (linkClientConsultation) use this newclientKey to replace old clientKey values equal to 36 or 38. These numbers are drawn from commands on the form called Me.clientAkey.Value and Me.clientBkey.Value
updatequery = "UPDATE linkClientConsultation SET clientKey = " & newclientKey & " WHERE clientKey IN (" & Me.clientBkey.Value & "," & Me.clientAkey.Value & ");"
DoCmd.RunSQL updatequery
The Debug.Print version of the query looks like this:
UPDATE linkClientConsultation SET clientKey = 41 WHERE clientKey IN (36,38);
However, while I'd expect this to replace the value of clientKey in the linkClientConsultation where it equals 36 or 38 with 41, it only replaces one of the two values - always the first of the two numbers but not both. Is this a syntax thing? Or a order of operations thing?
Sorry if this is a repeat.