I am trying to build a form to update fields in a table based on customer input in a form. The form has a criteria field, which is used to search for matching entries then an update field to update another Table field. My problem is that I cannot get the update to work when I reference the fields from the form. Here is the code:
Code:
Dim db As Database
Dim strSQL As String
Set db = CurrentDb
Set dbs = CurrentDb
Dim uiTAGNAME As String
Dim uoX_NAM As String
Forms![Prefill Xmtr Data]!TxtCPointTagname.SetFocus
uiTAGNAME = Forms![Prefill Xmtr Data]!TxtCPointTagname.Text
Forms![Prefill Xmtr Data]!TxtQTransmitter.SetFocus
uoX_NAM = Forms![Prefill Xmtr Data]!TxtQTransmitter.Text
Debug.Print uiTAGNAME
Debug.Print uoX_NAM
' [" + table2 + "]
' suggestion from stackoverflow with format used in udatedata
strSQL = "UPDATE [IO Data] SET [io data].x_nam = '" & uoX_NAM & "' " & _
"WHERE [IO Data].tagname Like 'bkr7*';"
Debug.Print strSQL
db.Execute strSQL
When I set a break, I can view the value of uoX_NAM, and it is updated from the form correctly.
I'm pretty sure I have the form field referenced incorrectly, but I have tried various other methods, none of which update the table.
The output of the Debug.Print strSQL is (aaa is the text I input into the form field TxtQTransmitter):
UPDATE [IO Data] SET [io data].x_nam = 'aaa' WHERE [IO Data].tagname Like 'bkr7*';
If I try the following code, the correct fields update, but it is not the entry from the form:
Code:
'this updates the correct fields
db.Execute "UPDATE [IO Data] SET [io data].x_nam = 'BRKRCMD'" & _
"WHERE [IO Data].tagname Like 'bkr7*';"
So my problem appears to be in how I reference the uoX_NAM variable.
Or possibly in how I am updating my table [IO Data]? But the table updates fine if I am not taking the value from the form.