Solved

Using UPDATE statement in Access VBA

Posted on 2014-11-13
3
146 Views
Last Modified: 2014-11-13
I am having a problem getting the below statement to work.  It doesn't give me an error but also does not update the value in my table.

strSQL = "Select * from [tblSourcedHires] where SourceHireID = " & intSourceHireID & " "

                    Set rs = db.OpenRecordset(strSQL)

                        If rs.RecordCount > 0 Then

                            strSQL = "UPDATE [tblSourcedHires] SET(RebateApplied) = " & strRebateApplied & " where SourceHireID = " & intSourceHireID & ""

                            db.Execute (strSQL)
                        End If

Open in new window

0
Comment
Question by:marku24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40441257
Is this supposed to only update a single record, or multiple?
strSQL = "SELECT * from [tblSourcedHires] " _
       & "WHERE SourceHireID = " & intSourceHireID

Set rs = db.OpenRecordset(strSQL)

While not rs.EOF
    rs.Edit
    rs!RebateApplied = strRebateApplied
    rs.Update
    rs.movenext 
WEND

rs.Close
Set rs = nothing

Open in new window

0
 

Author Comment

by:marku24
ID: 40441266
single record
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40441299
The syntax I provided above would handle single or multiple, although I prefer to use an update query if there are multiples.

Or you could simply use:
strSQL = "UPDATE [tblSourcedHires] " _
     & "SET [RebateApplied] = " & strRebateApplied & " " _
     & "WHERE SourceHireID = " & intSourceHireID
debug.print strsql
Currentdb.Execute strsql, dbfailonerror

Open in new window

If strRebateApplied is actually a string, then you would probably want to use:
strSQL = "UPDATE [tblSourcedHires] " _
     & "SET [RebateApplied] = '" & strRebateApplied & "' " _
     & "WHERE SourceHireID = " & intSourceHireID
debug.print strsql
Currentdb.Execute strsql, dbfailonerror

Open in new window


'note that this latter version contains single quotes.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question