Update doesn't hit table from form button even though recordset closed (1 Viewer)

Margarita

Registered User.
Local time
Today, 17:41
Joined
Aug 12, 2011
Messages
185
Hello,
I am in for a huge headache because one of the users just discovered that the form that we use to update two tables isn't updating one of the tables. I was very careless during testing, so now we have a bunch of updates to trace and put in manually, so I am feeling pretty awful and ashamed. Luckily, they can't pay me any less than they do- it's just not possible, so I am not expecting any severe punishment.

Here is the problem:

the user types in a string into an unbound textbox and clicks an update button which is supposed to run on both tables.

-the first update happens to a table that is not linked to the form and is not open and therefore it's just a simple update sql statement.

-the second update happens to a recordset which is open and displayed on a subform of this same form. So I assume that I first need to close the recordset so I can update the table. I thought that I was accomplishing this by setting the recordsource of the subform to "', then running the update sql, and then resetting the recordset back to the original query. However, this does not work. I still get the message box "you are about to update 0 rows" when I know it's supposed to update 1 row, no more, no less. Would someone be able to look at the code and let me know what I am getting wrong? All the data types are matching, by the way.
Thank you!!

PHP:
'update in Table1
DoCmd.RunSQL "Update Table1 set Inv= '" & Me.InvUpdate & "', " & _
" Comment= '" & Me.UpdateInvComment & "' where Inv like '" & Me.Inv & "' and " & _
"[VN] like '" & Me.VN & "';"
 
'make the details form invisible and set its source object to nothing, so the details form can be essentially closed
'and therefore the underlying table can be updated
 
Me. InvoiceDetails_Sub.Form.RecordSource = ""
Me. InvoiceDetails_Sub.Visible = False
 
 'update Table2
DoCmd.RunSQL "Update Table2 set Inv= '" & Me.InvUpdate & "', " & _
" Comments= '" & Me.UpdateInvComment & "' where VN like '" & Me.VN & "' and inv like '" & _
Me.Inv & "';"
 
'reset the details form sourceobject and make it visible
Me. InvoiceDetails_Sub.Visible = True
Me. InvoiceDetails_Sub.Form.RecordSource = "InvoiceDetails_Sub"

I also tried Me. InvoiceDetails_Sub.SourceObject= "" but it still says "about to update 0 rows."
 
Last edited:

JHB

Have been here a while
Local time
Today, 23:41
Joined
Jun 17, 2012
Messages
7,732
It is a "s" " Comments= '" & Me.Updat...
could it be that?
 

Sketchin

Registered User.
Local time
Today, 14:41
Joined
Dec 20, 2011
Messages
575
Perhaps make these changes:

DoCmd.RunSQL "Update Table2 set Inv= " & Me.InvUpdate & " , " & _
" Comments= " & Me.UpdateInvComment & " where VN like " & Me.VN & " and inv like " &
_
Me
.Inv & " ;"


Just removed the single quotes
 

Sketchin

Registered User.
Local time
Today, 14:41
Joined
Dec 20, 2011
Messages
575
I had a similar problem once and I had to add:

If Me.Dirty Then Me.Dirty = False - before the sql statement
 

Margarita

Registered User.
Local time
Today, 17:41
Joined
Aug 12, 2011
Messages
185
It is a "s" " Comments= '" & Me.Updat...
could it be that?


Hi JHB, no, unfortunately that's not the issue- Comments is the actual name of the field.
Thanks!
 

Margarita

Registered User.
Local time
Today, 17:41
Joined
Aug 12, 2011
Messages
185
Perhaps make these changes:

DoCmd.RunSQL "Update Table2 set Inv= " & Me.InvUpdate & " , " & _
" Comments= " & Me.UpdateInvComment & " where VN like " & Me.VN & " and inv like " &
_
Me.Inv & " ;"


Just removed the single quotes


I tried it without the single quotes and also tried chr(34) instead of quotes. Didnt' do it...
Thanks for the suggestion!
 

Margarita

Registered User.
Local time
Today, 17:41
Joined
Aug 12, 2011
Messages
185
I had a similar problem once and I had to add:

If Me.Dirty Then Me.Dirty = False - before the sql statement


Hi Sketchin, I just tried adding the line that you suggested, but unfortunately, it still does the same thing- no error, no nothing, just says that it will update 0 rows..
Thank you for the suggestion!
 

JHB

Have been here a while
Local time
Today, 23:41
Joined
Jun 17, 2012
Messages
7,732
Have you tried to see what the values you are updating?
Why are you using like, (like "abc*" or like "abc?")?

MsgBox("Update Table2 set Inv= '" & Me.InvUpdate & "', " & _
" Comments= '" & Me.UpdateInvComment & "' where VN like '" & Me.VN & "' and inv like '" & _
Me
.Inv & "';")
 

Margarita

Registered User.
Local time
Today, 17:41
Joined
Aug 12, 2011
Messages
185
Have you tried to see what the values you are updating?
Why are you using like, (like "abc*" or like "abc?")?

I am using exact strings, no wildcards. I know for a fact that the data is in there. I created a dummy record for testing and am trying the update using exact strings, but it won't update.
Thanks.
 

JHB

Have been here a while
Local time
Today, 23:41
Joined
Jun 17, 2012
Messages
7,732
Post the string from:
MsgBox("Update Table2 set Inv= '" & Me.InvUpdate & "', " & _
" Comments= '" & Me.UpdateInvComment & "' where VN like '" & Me.VN & "' and inv like '" & _
Me
.Inv & "';")
and the record you want to update.
 

Sketchin

Registered User.
Local time
Today, 14:41
Joined
Dec 20, 2011
Messages
575
Does the SQL look correct if you do a debug.print strSQL?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:41
Joined
Feb 19, 2002
Messages
43,301
1. Why is the identical data stored in two tables?
2. Why are you not using a bound form to update at least one of them? It is really poor practice to run an update query to update the current bound record.
3. Why are you using Like without any wild card characters? This indicates that you shouldn't be using Like at all but should be using = instead.
4. Why are you updating the same field you are using in the criteria? "Inv"
 

Users who are viewing this thread

Top Bottom