Results 1 to 14 of 14
  1. #1
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85

    Update Query

    Is it possible to run an update query from a form? I have a form that brings up a drop down list of peoples names that are sorted by date of last work. When the person has worked the new date is entered. Is there a way that I can then push a button and a query would run that would update the table with the new date and only the employee that worked. So only one line on the table?



    What would the query look like?

    In the table there are multiple fields but I only need to update [Last Worked] with the coresponding [Employee Name]

    Any help would be very much appreciated.

    Brad

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Sure; start creating an update query, and in the spots where you want to refer to the form, right-click and select Build to have the expression builder help you with the syntax.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    But how do I set the criteria to select the individualy name that was chosen in the drop down list?

    My Update Query at the moment

    Field: LastCalled
    Table:tblEmployee
    Update To: Now()
    Criteria:
    or:

    I want the criteria to tell it only to update [tblEmployee].[LastCalled] by using [frmOvertimeCallIn].[EmployeeNames]

    How do I create that criteria?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Like I said, right-click in the criteria area, select Build, and point to the combo.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    So this is what I have and I get an error which says Data type mismatch in criteria expression.

    Field: LastCalled
    Table:tblEmployee
    Update To: Now()
    Criteria:[Forms]![frmOvertimeCallIn]![EmployeeNames]
    or:

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    It would help to see the SQL, but it appears you may have the criteria on the date field instead of the employee field?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    ok I'm lost, I am trying to do this as a query? Should I be doing this a different way? Could you give me an example on how it should be written? Everything I showed you is how it is on the query.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    What I'm describing is a query. In design view, you'd see 2 fields, the date field you want to update and the employee field you want the update restricted to. The date field would have an entry in the Update To area, the employee would have that form reference in the criteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849

  10. #10
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    Thank you I might have got it.. Thanks for your patience.

  11. #11
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    So I am getting the following errors now. I think its because the names I am using is coming from the same table that I am trying to update with a date with my query. Any help would be appreciated.

    Click image for larger version. 

Name:	access error.png 
Views:	5 
Size:	20.9 KB 
ID:	12201

    Click image for larger version. 

Name:	access error 2.png 
Views:	4 
Size:	15.8 KB 
ID:	12202

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    That can be problematic. You might try explicitly saving the current record before running the query. I don't use macros, but I think it's under RunCommand.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    ok, is there a piece of code I could write that would run a query when the form closes that could look at the last record [Specific Form Feild] and then update a table. My issue is the table is open that I'm trying to write too. so if I close the record,mu query won't work because it looks at the record open and runs the query for the name chosen and a date entered. if the record is closed it can't run that query, to update the table?

    Make sense??

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Did you try saving the record before running the query? It could simply be that the form is dirty, which will lock the record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Update query won't update table
    By bonesie in forum Access
    Replies: 6
    Last Post: 01-15-2013, 05:22 PM
  2. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  3. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  4. Replies: 1
    Last Post: 08-19-2011, 12:16 PM
  5. Update Query- selective update?
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-29-2009, 11:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums