Update Record SQL

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Update Record SQL

Post by D Willett »

I'm getting a syntax error with the following:

Code: Select all

Private Sub CmdUpdateRecord_Click()
DoCmd.RunSQL "Update tblEST SET EnquiryInfo WHERE JobID=me.txtjobid"
End Sub
The record already exists in tblEst ( JobID ), the SQL should add the contents of txtEnquiryInfo from this form to EnquiryInfo in tblEst for the existing record.

Kind Regards
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78557
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Update Record SQL

Post by HansV »

Happy New Year, Dave!

1) You have to place Me.txtJobID outside the quotes.
2) You have to set EnquiryInfo to something. For example:

Code: Select all

Private Sub CmdUpdateRecord_Click()
    DoCmd.RunSQL "Update tblEST SET EnquiryInfo=Null WHERE JobID=" & Me.txtJobID
End Sub
to clear EnquiryInfo, or

Code: Select all

Private Sub CmdUpdateRecord_Click()
    DoCmd.RunSQL "Update tblEST SET EnquiryInfo=" & Chr(34) & Me.txtEnquiryInfo & Chr(34) & " WHERE JobID=" & Me.txtJobID
End Sub
to set EnquiryInfo to the value of a text box on your form. This assumes that EnquiryInfo is a text field and JobID is a number field.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Update Record SQL

Post by D Willett »

Cheers Hans

I can never work out SQL.... bugs me whenever I want to use it.

Thanks again :-)

(BTW --- Happy New Year )
Cheers ...

Dave.

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Update Record SQL

Post by D Willett »

Hi Hans
Could do with a little more SQL help.

1. Update the field [Status] in tblEst to "A" Where JobID=" & Me.JobID
2. Update the field [A-Date] in tblEst to Date() Where JobID=" & Me.JobID

I tried a couple of attempts without success, see below :hairout:

DoCmd.RunSQL "Update tblEST SET Status=A WHERE JobID=" & Me.JobID
DoCmd.RunSQL "Update tblEST SET Status=" & Chr(34) & A & Chr(34) & " WHERE JobID=" & Me.JobID
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78557
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Update Record SQL

Post by HansV »

Your last SQL should work. Alternatively:

Code: Select all

DoCmd.RunSQL "Update tblEST SET Status='A' WHERE JobID=" & Me.JobID
The second is:

Code: Select all

DoCmd.RunSQL "Update tblEST SET [A-Date]=Date() WHERE JobID=" & Me.JobID
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Update Record SQL

Post by D Willett »

Got it !!!

Found a useful link to study which should give me some help with future problems :innocent: hopefully... :grin:

https://www.fmsinc.com/MicrosoftAccess/ ... SQL_Syntax

Once again thanks
Cheers ...

Dave.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Update Record SQL

Post by Rudi »

D Willett wrote:Got it !!!

Found a useful link to study which should give me some help with future problems :innocent: hopefully... :grin:

https://www.fmsinc.com/MicrosoftAccess/ ... SQL_Syntax

Once again thanks
Here is another useful quick guide to SQL for Access (with syntax samples)
http://www.tutorialspoint.com/sql/sql-quick-guide.htm
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Update Record SQL

Post by D Willett »

Thanks Rudi, saved to favourites for future reference.

Regards
Cheers ...

Dave.