Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sub UpdateX() 
     
        Dim dbs As Database  
     
        Set dbs = OpenDatabase("SOShops.mdb") 
         
        dbs.Execute "UPDATE Employees " _ 
            & "SET Payrate = 12 " _ 
            & "WHERE DaysAtWork= 10 " _
            & "WHERE HoursePerDay = 8 ;" 
             
        dbs.Close 
     
    End Sub


What I have tried:

I tried to add another criteria (namely "HoursPerDay") to the WHERE Clause to narrow down on my choice but to no avail.
Posted
Updated 26-Apr-23 18:50pm

How about adding an AND clause?
SQL
UPDATE Employees
    SET Payrate = 12
    WHERE DaysAtWork = 10
      AND HoursPerDay = 8
 
Share this answer
 
Comments
Jeffery Tengen 27-Apr-23 1:50am    
Appreciate your help. How exactly could i put this piece in VBA Code, please?
Dave Kreskowiak 27-Apr-23 7:37am    
You can't be serious? Look at your own code and see where that one piece of the puzzle fits.
Jeffery Tengen 27-Apr-23 8:44am    
Appreciate it
To expand on what Dave has rightly said...
An SQL statement can only have one WHERE clause, so you need to expand the WHERE expression using the logical operators that SQL supports: AND and OR.

They both have the same format:
SQL
WHERE <Expression1> <Logical operator> <Expression2>
AND combines expressions so the result is TRUE only if both expressions are TRUE. If the first expression is FALSE, the second is not evaluated.

OR combines expressions so the result is TRUE if either of the expressions is TRUE. If the first expression is TRUE the second is not evaluated.

You can chain there together along with brackets to get complex WHERE clauses:
SQL
WHERE a AND b AND (c OR d)
Will be TRUE only if a and b are TRUE, and at least one of c and d are TRUE

See here: SQL Operators[^]
 
Share this answer
 
Comments
Jeffery Tengen 27-Apr-23 1:51am    
Appreciate your clarity. How exactly could jot this piece in VBA Code, please?
OriginalGriff 27-Apr-23 2:12am    
That's the point, you don't - you write it in SQL code which VB sends to the database engine.

If you write it in VB code, then the whole DB table needs to be pulled from the server and processed locally, which is monumentally inefficient.
Jeffery Tengen 27-Apr-23 2:28am    
Very Much Appreciate it sir. It is working fine now.
OriginalGriff 27-Apr-23 3:19am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900