Connecting Tech Pros Worldwide Forums | Help | Site Map

Update Query in VBA updates field to -1!?

Member
 
Join Date: Oct 2006
Posts: 34
#1: Jul 10 '07
Hi,

I'm trying to run an update query in vba and i'ts not working. It does the update but the [Limit Level 2] field is updated to "-1".

here's the query:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim stDocName As String
  3. Set rst = New ADODB.Recordset
  4.         stDocName = "SELECT * FROM [Limit Table] WHERE [ID]=" & txtID.Value & ""
  5.         rst.Open stDocName, CurrentProject.Connection
  6.  
  7.         If txtID = "" Or IsNull(txtID) Then
  8.         stDocName = MsgBox("Click on the Row that you want to Update")
  9.     Else
  10.         stDocName = "UPDATE [Limit Table] SET [Limit Level 1]='" & ComboLevel1.Value & "',[Limit Level 2]='" & ComboLevel2.Value & "' AND [Primary/Secondary]='" & ComboPS.Value & "',[Limit Type]='" & ComboType.Value & "',[Limit Amount]='" & txtAmount.Value & "',[Limit Currency]='" & ComboCurrency.Value & "',[Limit Approval Date]='" & txtDate.Value & "' WHERE [ID]=" & txtID
  11.         DoCmd.RunSQL stDocName
  12.         lstTEST.Requery
  13.  
  14.     End If 
[Limit Level 2] is a combobox with a dropdown that depends on what has been chosen in [Limit Level 1]. I have put the code for this in the 'gotfocus' property of ComboLevel2. I think this might have something to do with the problem, although the dropdown works perfectly.

any ideas?

regards,
Riun

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#2: Jul 17 '07

re: Update Query in VBA updates field to -1!?


Is txtID a text or a number field?

You haven't declared rst as a variable (i.e.)

Dim rst As ADODB.Recordset

In your update statement the syntax is wrong

"UPDATE [Limit Table] SET [Limit Level 1]='" & ComboLevel1.Value & "', [Limit Level 2]='" & ...."

it should be

"UPDATE [Limit Table] SET [Limit Level 1]='" & ComboLevel1.Value & "' AND [Limit Level 2]='" & ...."
Reply