Updating two fields from one form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3665

    #16
    First, when posting a procedure, please include the entire procedure (from Private Sub all the way to End Sub). This allows us to see everything that is going on (even though it looks like we have mostly everything.

    The easiest way to do this is to have the SQL statement look for the person in question. But, before you start aiming at random possibilities, think about 1) what we have done with some of your other code when dealing with your employees in trying to streamline your code (Hint: use a function which receives an employee ID....) and 2) what similarities and what differences there would be which such a design. Plan it out, then design the procedure.

    No--this is not an "answer", but it is guiding you to a solution, based upon principles we have already covered.

    Comment

    • didacticone
      Contributor
      • Oct 2008
      • 266

      #17
      i have actually followed your advice and created a couple other functions for the database. With this case being we are referencing a recordset i am having trouble figuring out the logic... i need to understand that first before i create the function, so im kind of stuck before i got started lol.

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3665

        #18
        Look at line 6 in your code in post #15. How would you modify the SQL statement to pull one employee's record. Then, if you know how to pull one employee's record, you should be able to pull any employee's record using a variable fed to that query's WHERE statement. Make sense?

        Also, I thought your employees were referenced using an index in the employee's table?? Yes???

        Comment

        • didacticone
          Contributor
          • Oct 2008
          • 266

          #19
          so i altered the sql statement to reference a specific employee, i believe correctly? I am stuck on how to pull any employee though?

          Code:
          Private Sub cmdHalfVaca_Click()
          Dim MyDB As DAO.Database
          Dim rst As DAO.Recordset
          Dim strSQL As String
          
          Set MyDB = CurrentDb
          
          
          strSQL = "SELECT * FROM tbl_daysoff WHERE employee = ""Joe Smith"""
          
          Set rst = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
           With rst
          
              .Edit
                
              ![vacation] = ![vacation] - 0.5
              .Update
              End With
          
          rst.Close
          Set rst = Nothing
          
           
          End Sub
          And yes the employees are referenced using an index in the employees table.

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3665

            #20
            Refer back to one of your previous posts.

            We created a Function that received an Employee ID, performed actions on that Employee ID and then returned back to the original procedure.

            Remember, one step at a time. Don't get hung up on the SQL statement just now; think about the structure of your code first. But I will tell you that you have the general idea in your post above.

            Comment

            Working...