Results 1 to 3 of 3
  1. #1
    Twinnie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    18

    Update Checkbox Value In Table Based On Combo Box Selection

    I have a combobox with staff names and for each selected staff name, the second combo box should not display the staff name that has been selected.


    To achieve this, I put a checkbox inside the table that contains the staff details and I wrote this update query.

    UPDATE Staff_Details SET Staff_Details.YesNo = -1
    WHERE (((Staff_Details.FullName)=[Forms]![AccountabilityForm]![cboStaffName]));


    The staff table is Staff_Details
    The Field on the table to be checked depending on whether the staff has been selected or not is YesNo.
    The form name is AccountabilityForm and the combobox name is cboStaffName.
    I want the corresponding checkbox for the selected staff on the combobox to be ticked immediately the staff is selected and I want to write a select query that will only display staff names without an Active checkbox for the second combo selection.
    How can I achieve this?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Really should use ID field in criteria instead of name. The ID field should be the first column of the combobox and hidden. Should be saving ID instead of name into the data table. Names make very poor unique identifiers/key fields.

    Combobox RowSource:

    SELECT StaffID, FullName FROM Staff_Details WHERE YesNo = False;

    I use only VBA, not macros. Code to set the checkbox field and requery the combobox:

    CurrentDb.Execute "UPDATE Staff_Details SET YesNo = True WHERE StaffID=" & Me.cboStaffName
    Me.cboStaffName.Requery
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Try this for your SQL statement.


    DoCmd.SetWarnings False
    DoCmd.RunSQL "UPDATE Staff_Details SET Staff_Details.YesNo = True " & _
    "WHERE (((Staff_Details.FullName)='" & Me.cboStaffName.Value & "'));"
    DoCmd.SetWarnings True
    For your query just enter True for your YesNo criteria.

    HTH

    Didn't see your post June!
    Last edited by burrina; 10-28-2014 at 03:56 AM. Reason: Oops

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

Similar Threads

  1. Replies: 5
    Last Post: 04-29-2013, 04:23 PM
  2. Replies: 1
    Last Post: 10-25-2012, 12:58 PM
  3. Replies: 1
    Last Post: 11-03-2011, 11:56 PM
  4. Replies: 3
    Last Post: 10-31-2011, 04:54 PM
  5. Update table based on List Box selection
    By tpcervelo in forum Forms
    Replies: 0
    Last Post: 11-04-2010, 01:32 PM

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