Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2010
    Posts
    14

    Unanswered: How do I get checkboxes of duplicated records to also be checked?

    I have the below code that, if a checkbox representing an additional available time on a form is checked then the record is duplicated and that additional available time is added into the time field of the new record. On the form there are numerous checkboxes that the user can select. These checkboxes represent any QC issues the product may have had when the record was created. Those checkboxes on the form are on several tabs of a multi-tab form. On the main part of the form I have a text box that shows what checkboxes were checked on the various tabs. The text box will show the user all the checkboxes they selected on the various tabs all in one place making it easier for the user to verify they have selected all the checkboxes they intended to. Because the user has to select different checkboxes on multiple tabs of the form I wanted a textbox on the main form to show the user everything they selected on the other tabs.

    The code duplicates the record and changes the Time field to represent the additional time that the user selected but the checkboxes on the new record aren't selected like they are on the record being duplicated. There are a lot of checkboxes on the various tabs so instead of writing code for every checkbox that could be checked I think it would be easier to have code look at the values placed into the textbox on the main for and to have that code then check those checkboxes on the duplicated record.

    Hopefully this makes sense. Below is the entire code that make this work so far. What code would I use to have the textbox evaluated when the record is created and to have the checkboxes on the form that represent the values in the textbox to also be checked when the new record is created?

    Code:
    Option Compare Database
    Option Explicit
    Private Function SubAddRecords()
    'this function will call the Subroutine AddRecords_Click() code below so that I can use this _
    function to call from the VCR control macros on the main form.
    Call AddRecords_Click
    End Function
    Sub AddRecords_Click()
    Dim varTime As String
    If cb630AM.Value = True Then
        varTime = "6:30am"
        Call addentry(varTime)
        End If
    If cb830AM.Value = True Then
        varTime = "8:30am"
        Call addentry(varTime)
        End If
    If cb1030AM.Value = True Then
        varTime = "10:30am"
        Call addentry(varTime)
        End If
    If cb1230PM.Value = True Then
        varTime = "12:30pm"
        Call addentry(varTime)
        End If
    If cb230PM.Value = True Then
        varTime = "2:30pm"
        Call addentry(varTime)
        End If
    If cbEndDays.Value = True Then
        varTime = "End-Days"
        Call addentry(varTime)
        End If
    If cb630PM.Value = True Then
        varTime = "6:30pm"
        Call addentry(varTime)
        End If
    If cb830PM.Value = True Then
        varTime = "8:30pm"
        Call addentry(varTime)
        End If
    If cb1030PM.Value = True Then
        varTime = "10:30pm"
        Call addentry(varTime)
        End If
    If cb1230AM.Value = True Then
        varTime = "12:30am"
        Call addentry(varTime)
        End If
    If cb230AM.Value = True Then
        varTime = "2:30am"
        Call addentry(varTime)
        End If
    If cbEndNights.Value = True Then
        varTime = "End-Nights"
        Call addentry(varTime)
        End If
    End Sub
    Private Function addentry(varTime As String)
    Dim db As Database
    Dim rs As Recordset
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblProductionNumbers", dbOpenDynaset)
    rs.AddNew
    rs("ManHoursID") = Me.ManHoursID.Value
    rs("ProductionDate") = Me.ProductionDate.Value
    rs("TimeID") = varTime
    rs("Line#ID") = LineID.Value
    rs("ProductID") = Me.ProductID.Value
    rs("OperatorID") = Me.OperatorID.Value
    rs("TailOffID") = Me.TailOffID.Value
    rs("LF Run") = Me.[LF Run].Value
    rs("LF Produced") = Me.[LF Produced].Value
    rs("Comments") = Me.Comments.Value
    rs.Update
    rs.Close
    db.Close
    End Function
    Private Function ClearCheckBoxes()
    cbEndNights.Value = False
    cb630AM.Value = False
    cb830AM.Value = False
    cb1030AM.Value = False
    cb1230PM.Value = False
    cb230PM.Value = False
    cbEndDays.Value = False
    cb630PM.Value = False
    cb830PM.Value = False
    cb1030PM.Value = False
    cb1230AM.Value = False
    cb230AM.Value = False
    End Function
    Private Sub cb630AM_Click()
    If cboTime = "6:30am" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb630AM.Value = False
    Else
    End If
    End Sub
    Private Sub cb830AM_Click()
    If cboTime = "8:30am" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb830AM.Value = False
    Else
    End If
    End Sub
    Private Sub cb1030AM_Click()
    If cboTime = "10:30am" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb1030AM.Value = False
    Else
    End If
    End Sub
    Private Sub cb1230PM_Click()
    If cboTime = "12:30pm" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb1230PM.Value = False
    Else
    End If
    End Sub
    Private Sub cb230PM_Click()
    If cboTime = "2:30pm" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb230PM.Value = False
    Else
    End If
    End Sub
    Private Sub cbEndDays_Click()
    If cboTime = "End-Days" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cbEndDays.Value = False
    Else
    End If
    End Sub
    Private Sub cb630PM_Click()
    If cboTime = "6:30pm" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb630PM.Value = False
    Else
    End If
    End Sub
    Private Sub cb830PM_Click()
    If cboTime = "8:30pm" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb830PM.Value = False
    Else
    End If
    End Sub
    Private Sub cb1030PM_Click()
    If cboTime = "10:30pm" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb1030PM.Value = False
    Else
    End If
    End Sub
    Private Sub cb1230AM_Click()
    If cboTime = "12:30am" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb1230AM.Value = False
    Else
    End If
    End Sub
    Private Sub cb230AM_Click()
    If cboTime = "2:30am" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cb230AM.Value = False
    Else
    End If
    End Sub
    Private Sub cbEndNights_Click()
    If cboTime = "End-Nights" Then
    DoCmd.Beep
    msgbox "You cannot select the SAME TIME twice. Please try your selections again"
    cbEndNights.Value = False
    Else
    End If
    End Sub
    This code is the code that looks at a cherckbox and if it is selected it will place the name of the control in the textbox.

    Code:
    Private Sub ImajePrinterJetNeedsAdjustment_AfterUpdate()
    
          '--------------------------------------------
          ' Procedure : ImajePrinterJetNeedsAdjustment_AfterUpdate
          ' Author    : Chris D. Mallea
          ' Date      : 10/28/2010
          '
          '
          '--------------------------------------------
    10    On Error GoTo ImajePrinterJetNeedsAdjustment_AfterUpdate_Error
    
    20        If Me.ImajePrinterJetNeedsAdjustment = -1 Then
    30            Me.UserSelectedTabItems = Me.UserSelectedTabItems & _
                      "ImajePrinterJetNeedsAdjustment" & vbNewLine
    40        Else
    50            Me.UserSelectedTabItems = Replace(Me.UserSelectedTabItems, _
                      "ImajePrinterJetNeedsAdjustment" & vbNewLine, "")
    60        End If
    
    
    ImajePrinterJetNeedsAdjustment_AfterUpdate_Exit:
    70        Exit Sub
    ImajePrinterJetNeedsAdjustment_AfterUpdate_Error:
    80    msgbox "Error Line: " & Erl & vbCrLf & "Error: (" & Err.Number & ") " & _
              Err.Description & vbCrLf & "ImajePrinterJetNeedsAdjustment_AfterUpdate" & vbCrLf & "Form_frmProductionNumbers", vbCritical
    
    90        Resume ImajePrinterJetNeedsAdjustment_AfterUpdate_Exit
    
    End Sub

  2. #2
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    Your data are not normalized. Please read up on normalization in the Help file. Since time and other factors are not the same level - time can be more than one record, the other items are always one record - remove the time recording from both the table and the form, and make a separate form and table for them. (In a query/report you can always calculate the total time.)

    The tblTimeRecords table (my own invention) and the main table should have a relationship based on some unique field in the main table. If you have trouble with this, read up on Relationships as well. Microsoft outdid themselves in the Access Help file. If you have further trouble, don't hesitate to ask here.

    Besides the above, and maybe even before the above, I'm curious why you need so many checkboxes with time increments. What does the user show with them? Your code may be simplified, depending on what you're doing.

    Sam
    Last edited by Sam Landy; 06-07-12 at 18:12. Reason: Misunderstanding

  3. #3
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    In addition to what Sam said, you have not provided a complete explanation of the structure of your database. For example, are the checkboxes in the form bound to the form's record source? If so, you need to include the names of the fields in your duplicating function. If they are not bound, you will need to load the states of the checkboxes into global variables and use them when you display the new record. How you control that could prove to be tricky.
    10% of magic is knowing something that no-one else does. The rest is misdirection.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •