Results 1 to 9 of 9
  1. #1
    joycesolomon is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Posts
    11

    multiple check box values - update table

    hi all,

    Good morning.

    I do need some help with the vba programming.

    I have a form that has 4 check boxes. They all can be left null at a given time, or they all can be checked at the same time.

    each check box is tied to a column in the table. (image attached)Click image for larger version. 

Name:	image1.png 
Views:	15 
Size:	15.1 KB 
ID:	17506



    how do i send the value back from the form to the table, if the checkbox is checked?

    Here is the code i am using to insert the values from the form to the table.

    Code:
    CurrentDb.Execute "INSERT INTO Project (Initiator, InitDate, Program, Type,[Developer Name], EquipAff, [Project Description], Justification, ReqCompl, Notes) " & _
                      " VALUES ('" & Me.txtInitiator & "', """ & Me.txtInitDate & """, '" & _
                      Me.cboProgram & "', '" & Me.cboType & "', '" & Me.cboDeveloperName & "', '" & Me.txtEquipAff & "', '" & Me.MOCDescr & "', '" & _
                      Me.Justification & "', """ & Me.txtReqCompl & """, '" & Me.Notes & "')"
    The check boxes are named chkEnvironmental, chkSafety, chkCompliance, chkRunCritical.

    In the table , the columns are named Environ, Safety, Comp, Run

    Please help as i am not sure how to achieve this.

    Thanks in advance

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    If the form is bound to the table, each of the check box controls can be bound to a field in the table. No code would be needed. Any change made in the form will automatically be made in the table too.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    If the checkboxes on the form are bound to the fields (columns) in the table, then you don't need any code. The table is updated when you make the changes on the form, and move off that record. (The same is true of all the other values as well).

    If you want to include those values in the VBA insert statement, include the field names in the SQL Insert statement field list, and the form control names in the VALUES list, in addition to the ones you have. These ones will not have quotation marks:

    Code:
    CurrentDb.Execute "INSERT INTO Project (Initiator, InitDate, Program, Type,[Developer Name], EquipAff, [Project Description], Justification, ReqCompl, Notes, Environ, Safety, Comp, Run) " & _
                      " VALUES ('" & Me.txtInitiator & "', """ & Me.txtInitDate & """, '" & _
                      Me.cboProgram & "', '" & Me.cboType & "', '" & Me.cboDeveloperName & "', '" & Me.txtEquipAff & "', '" & Me.MOCDescr & "', '" & _
                      Me.Justification & "', """ & Me.txtReqCompl & """, '" & Me.Notes & "'," & _
    me.chkEnvironmental & ", " &  me.chkSafety & ", " &  me.chkCompliance & ", " & chkRunCritical & ")"
    
    HTH

    John

  4. #4
    joycesolomon is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Posts
    11
    John,

    This form is to enter new records. So i have set all the fields to be "unbound". Is that a bad idea?

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    "So i have set all the fields to be "unbound". Is that a bad idea?"

    No, not necessarily. It depends on what you are comfortable with, and if you reasonably comfortable with VBA. Having all the fields unbound gives you more flexibility, in that you only add a record when you really want to, after all checks and validations are done.

    John

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    I would not normally use an unbound form for data entry. I'm sure it will end up needing more code. I can't see what there is to be gained in that.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    joycesolomon is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Posts
    11
    john,

    Will i be using the same resolution you provided above to still insert new records with unbound field?

    I only reason why i did that was, i did not want to show all the records but purely wanted to only add a new record with this form.

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Yes, the code is the same (assuming all data is going into the same table, of course!)

    John

  9. #9
    joycesolomon is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Posts
    11
    It worked perfectly. thank you!

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

Similar Threads

  1. Find and update multiple values
    By chemthethriller in forum Forms
    Replies: 3
    Last Post: 04-22-2014, 01:15 PM
  2. Replies: 9
    Last Post: 08-15-2013, 04:28 PM
  3. check table, if exist then update another table
    By JeroenMioch in forum Programming
    Replies: 6
    Last Post: 07-06-2012, 09:12 AM
  4. Dynamic Check Boxes values from table
    By ktmjamal in forum Forms
    Replies: 1
    Last Post: 02-21-2011, 07:49 AM
  5. Update query to summarize multiple values
    By ser01 in forum Queries
    Replies: 3
    Last Post: 05-15-2010, 09:38 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