Results 1 to 6 of 6
  1. #1
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118

    Adding records by using checkbox

    Need help.


    The DB I have uses checkbox 2, 4, 6 in terms of how many days each job would take. These are the only 3 blocks of days that can be used so check boxes were made to ensure they only choose this block of days

    However, when for example 2 is check off (for 2days job will go on) I want duplicate records to generate for each day. Make sense?

    So 9/27/2013 is the start day of Job. I check off box 4
    Then 9/28/2013
    9/29/2013
    and
    9/30/2013
    is automatically generated with duplicated information.

    We don't want to keep hitting the duplicate button and having to change the date for 6 jobs.

    Is this possible?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    The only way I can see to accomplish this is through the VBA editor. You will need to write a sub routine that will analyze what the user select and then update the appropriate records. Your sub routine can fire via a click event or maybe an after update. Click event will probably be safest.

    You can update records using an SQL UPDATE or a loop command.

  3. #3
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    I so hoped I was this talented. Can u assist me with writing the subroutine or direct me where I can go?
    Appreciate it :-)

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    This is a complicated procedure you are trying to accomplish. In order for the DB to perform the request there will need to be proper table design. Relations are key here so you have a WAY to write the code.

    Reading your question in post #1 raises concern that your table structure may not be what it could be. You may be working harder than need be. In fact, the solution you seek and the route you are considering as a solution may be the product of poor design.

    I would start by rethinking why you need to duplicate records. You may not need to. However, even if you do not need to duplicate records you will still need to understand how to query the results you desire from the tables. So, catch 22. No way around not knowing how to code.

    You can start with researching a CASE statement. You present a scenario where a user says something. In the CASE they say, "4", you need to pass that value to the program. Once the program has the user's input stored in a variable, you can begin doing something with it.

    In your case I may start by declaring a variable that the program can store the user's input in.

    Code:
    Dim intUserInput as Integer
    Here I imagine an intuitive name to name my variable and assign the data type Integer to it. This example is not addressing related issues to data types and validation and truncated values.

    Now I can pass the user input to the declared variable.

    Code:
    intUserInput = Me.txtUserInput.Value
    The example assumes the user is typing data into a text box named txtUserInput within a form.

    Now you can apply a CASE statement to determine what to do with the user input.

    Code:
    CASE Select intUserInput
    
    Case "2"
    [Insert statement that does something twice]
    
    Case "4"
    [Insert statement that does something four times]
    
    Case Else
    MsgBox "The data base does not like your Input"
    
    End Select
    I suggest you play around with collecting user input and doing things with said input. You can build your own practice data bases to explore, IF THEN ELSE and CASE SELECT statements along with a MsgBox response. If this is something you feel comfortable with then you might want to do more exploring.

  5. #5
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    I was thinking of changing it as well to maybe a combo box not a check box. With the option 2, 4, 6.
    Depending on which is chosen is there a way to create duplicate records for that many future dates?

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    After you play around with user input for a while you will discover ways to control what the user can "Say" or "Tell" the DB to do. A combo box is a great way to control the options. Another approach would be an option group you create with the wizard. I generally don't recommend things like this because option groups hide what is really going on in a macro.

    Whatever you decide, I would stay away from assigning lookup fields to your tables. I was recently reminded this when I looked at an example that contained lookup fields.

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

Similar Threads

  1. Replies: 4
    Last Post: 06-24-2013, 03:36 AM
  2. Help about adding up sums using a checkbox.
    By MelonFuel in forum Forms
    Replies: 1
    Last Post: 06-29-2012, 06:16 AM
  3. Replies: 11
    Last Post: 03-16-2012, 11:46 AM
  4. Replies: 10
    Last Post: 01-10-2011, 07:52 PM
  5. Checkbox to sort records
    By homerj56 in forum Programming
    Replies: 1
    Last Post: 09-09-2010, 09:53 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