MS Access SQL Update Table

Malcolm17

Member
Local time
Today, 09:29
Joined
Jun 11, 2018
Messages
114
Hi,

I have a table called PLUs, I need to update the value of the field called Desc from an unbound field on a form.

I am trying the following line of code and cannot see what is wrong with it, please can you help?

<DoCmd.RunSQL "UPDATE PLUs SET Desc = Forms.EPOSControl.Starter1Description WHERE Code = '1118'">
or
<DoCmd.RunSQL "UPDATE PLUs SET Desc = Forms.EPOSControl.Starter1Description WHERE Code = Forms.EPOSControl.Start1Code">

The table is called PLUs
The form is called EPOSControl
The field to update from the form is called Starter1Description, it is on an unbound Form and unbound Text Box
The field to update in the table is called Desc (Stored as Text)
The field to select which row to update is called Code (Stored as Text)

I can manually update it in the table or by using an update query, so I believe it is my line of code that is wrong, but I can't see where.

Many thanks,

Malcolm
 
Hi,

I keep looking at this an cannot work it out, I have used code which I use in another database to do something similar, however I cannot get it to work, please could someone be so kind to look at this for me and put me out of my misery.

Many thanks,

Malcolm
 

Attachments

Desc is a reserved word and as such needs to be enclosed in square brackets.

you need to reference the value of your controls separately in your string

"UPDATE PLUs SET [Desc] = '" & Starter1Description & "' WHERE Code = '" & Start1Code & "'"
 
DoCmd.RunSQL "UPDATE PLUs SET [Desc] = '" & Forms.EPOSControl.Starter1Description & "' WHERE Code = '1118'"
 
Thank you for all your help, this has helped my problem, I didn't know that Desc was a reserved word - every day is a school day!

Malcolm
 
here is a list for most reserved words

 

Users who are viewing this thread

Back
Top Bottom