MS Access SQL Syntax

Hi I am trying to use SQL to update a table  (tEmailRx) with information from a form.  The table is laid out as:

CreateDate  - Date
MR - Number (long Int)
RxType - Text
Office - Text
Ws - Text

I am trying to use the following code:
    sSQL = "UPDATE tEmailRx tEmailRx.CreateDate = #" & Date & "#, tEmailRx.MR = " & Me.ID & ", tEmailRx.RxType='CL', tEmailRx.Office='" & sOffice & ",tEmailRx.Ws = Environ$(""computername"")"
    DoCmd.RunSQL sSQL

Open in new window

Which results in:

UPDATE tEmailRx tEmailRx.Date = #11-15-2017#, tEmailRx.MR = 126011, tEmailRx.RxType='CL', tEmailRx.Office='WB,tEmailRx.Ws = Environ$("computername")

But I am getting an error.  What am I doing wrong with my syntax?  SQL is a very weak link for me - Thanks!
thandelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
You need to use SET.
sSQL = " UPDATE tEmailRx SET tEmailRx.CreateDate = #" & Date & "#, tEmailRx.MR = " & Me.ID & ", tEmailRx.RxType='CL', tEmailRx.Office='" & sOffice & ",tEmailRx.Ws = '" & Environ$("computername") & "'"
    
DoCmd.RunSQL sSQL

Open in new window

0
thandelAuthor Commented:
Thank you, so silly but there must be a small error as now the error is syntax error missing operator in query expression "WB,tEmail.Rx.Ws = 'Jupiter"
0
NorieAnalyst Assistant Commented:
Strange, in the code you have tEmailRx.Ws but the error message says you have tEmail.Rx.Ws.

What happens if you use the field names without the table name in the SET part.
sSQL = " UPDATE tEmailRx SET CreateDate = #" & Date & "#, MR = " & Me.ID & ", RxType='CL', Office='" & sOffice & ",Ws = '" & Environ$("computername") & "'"
    
DoCmd.RunSQL sSQL

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

thandelAuthor Commented:
I modified to this

sSQL = " UPDATE tEmailRx SET tEmailRx.CreateDate = #" & Date & "#, tEmailRx.MR = " & Me.ID & ", tEmailRx.RxType='CL', tEmailRx.Office='" & sOffice & "',tEmailRx.Ws = '" & Environ$("computername") & "'"code]

Open in new window

Not getting any error but nothing is happening to the table.
0
thandelAuthor Commented:
I tried your code similar error
0
thandelAuthor Commented:
oh wait slightly different.... "Wb,Ws = 'Jupiter".
0
NorieAnalyst Assistant Commented:
I think there's a missing ' in what I posted.

Try this, I think I fixed it.
sSQL = " UPDATE tEmailRx SET CreateDate = #" & Date & "#, MR = " & "Me.ID" & ", RxType='CL', Office='" & "sOffice" & "',Ws = '" & Environ$("computername") & "'"

    
DoCmd.RunSQL sSQL

Open in new window

0
thandelAuthor Commented:
Well now its prompting me for a value of Me.Id
0
NorieAnalyst Assistant Commented:
Sorry, my mistake - it's late here.

Try this.

sSQL = " UPDATE tEmailRx SET CreateDate = #" & Date & "#, MR = " & Me.ID & ", RxType='CL', Office='" & sOffice & "',Ws = '" & Environ$("computername") & "'"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thandelAuthor Commented:
Is Update correct I want to keep adding a row to the table with this... I can't remember if update is what I need to do that.
0
thandelAuthor Commented:
Ah bingo that worked thanks... but it does seem to only  update the first row... I would like to add to the table with each execution
0
NorieAnalyst Assistant Commented:
UPDATE is for updating a table not adding to it, If you want to add to it then you need INSERT.

In fact if your UPDATE query had run successfully it might update every record in the table.
0
thandelAuthor Commented:
Oh I see, to make a insert would I just change Update to Insert?
0
NorieAnalyst Assistant Commented:
Not quite, the syntax is a bit different and there are different types of INSERT.

If you wanted to add a record with the values in your UPDATE query it might look something like this.
sSQL = " INSERT INTO tEmailRx (CreateDate, MR, RxType, Office, Ws)
sSQL = sSQL & " VALUES (#" & Date & "#, " & Me.ID & ",'CL', '" & sOffice & "','" & Environ$("computername") & "')"

Open in new window

0
thandelAuthor Commented:
OK thanks but trying the code no errors but no updates to the table either
0
NorieAnalyst Assistant Commented:
Can you post the rest of your code?
0
thandelAuthor Commented:
yes but not sure what part you need?  Its really press the button and the SQL runs.
0
thandelAuthor Commented:
Private Sub RxOpEmail_Click()
    sSQL = "INSERT INTO tEmailRx (CreateDate, MR, RxType, Office, Ws)"
    sSQL = sSQL & " VALUES (#" & Date & "#, " & Me.ID & ",'CL', '" & sOffice & "','" & Environ$("computername") & "')"
    DoCmd.RunSQL sSQL
End Sub

Open in new window

0
thandelAuthor Commented:
I'm sorry it is working!  I had the table open and assume it would refresh... even if I clicked on another row but it didn't.  When I closed and reopened the table it was visible.  I apologize for the over sight.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.