Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702

    Quote Originally Posted by PinkLady50 View Post
    Thanks to All! Got it working!
    Would you mind paying it forward by haring what you did to fix it.

  2. #17
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    Final Code!

    Code:
    Option Compare Database  '<-- should be at the top of every code page
    Option Explicit         '<-- should be at the top of every code page
    Private Sub cmdAddVAC_Click()
        
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim i As Variant
        Dim issuesValue As String, vacancyValue As String
        
        On Error GoTo ErrorHandler
        Set db = CurrentDb()
        Set rs = db.OpenRecordset("tblPerfIssues")
        If Len(Me.cboAnalyst & vbNullString) = 0 Or Len(Me.txtReportDate & vbNullString) = 0 Or Len(Me.cboContractNumber & vbNullString) = 0 Then
            MsgBox "Please fill in Analyst/Specialist, Report Date and Contract Number"
        Else
            If Me.lstContractorIssues.ItemsSelected.Count = 0 Then
                MsgBox "Please select at least one item from Contractor Issues"
            Else
                'loop through the multi select list box lstContractorIssues to get issues
                For Each i In Me.lstContractorIssues.ItemsSelected
                    issuesValue = issuesValue & ", " & Me.lstContractorIssues.ItemData(i)
                Next i
                'loop through the multi select list box lstVacancyReason to get reasons
                For Each i In Me.lstVacancyReason.ItemsSelected
                    vacancyValue = vacancyValue & ", " & Me.lstVacancyReason.ItemData(i)
                Next i
                issuesValue = Right(issuesValue, Len(issuesValue) - 2)
                vacancyValue = Right(vacancyValue, Len(vacancyValue) - 2)
                'All the fields are writing correctly to the table but the the 2 listboxes (ContractorIssues lstContractorIssues) (VACReason lstVacancyReason)
                With rs  '<<--!!!!
                    .AddNew
                  rs.Fields("AnalystSpec") = cboAnalyst.Value
                    rs.Fields("ReportDate") = Me.txtReportDate.Value
                    rs.Fields("ContractNumber") = Me.cboContractNumber.Column("0")
                    rs.Fields("Contractor") = Me.txtContractor.Value
                    rs.Fields("MATO") = Me.txtMATO.Value
                    rs.Fields("ContractorOnset") = Me.txtContractorOnset.Value
                    rs.Fields("ContractorResolved") = Me.txtContractorResolved.Value
                    rs.Fields("ContractorComments") = Me.txtContractorComments.Value
                    rs.Fields("ContractorIssues") = issuesValue
                    rs.Fields("VACTo") = Me.cboTOvac.Value
                    rs.Fields("VACCLIN") = Me.cboCLINvac.Column("2")
                    rs.Fields("VACCOR") = Me.txtCORVAC.Value
                    rs.Fields("VACMTF") = Me.txtMTFVAC.Value
                    rs.Fields("VACLabor") = Me.txtLaborvac.Value
                    rs.Fields("VACSite") = Me.txtSiteVAC.Value
                    rs.Fields("VACClinic") = Me.txtClinicalVAC.Value
                    rs.Fields("VACIndcov") = Me.txtIndHCW.Value
                    rs.Fields("MissedHours") = Me.txtIndHours.Value
                    rs.Fields("MissedShifts") = Me.txtCovHours.Value
                    rs.Fields("TOStart") = Me.txtTOStart.Value
                    rs.Fields("TOEnd") = Me.txtTOEnd.Value
                    rs.Fields("VACStart") = Me.txtVacFrom.Value
                    rs.Fields("VACEnd") = Me.txtVacTo.Value
                    rs.Fields("VACReason") = vacancyValue
                    rs.Fields("VACComments") = Me.txtVACComments.Value
                    rs.Update
                End With '<<--!!!!
            End If
        End If
    ErrorHandler_Exit:
        On Error Resume Next
        rs.Close
        Set rs = Nothing
        Set db = Nothing
        Exit Sub
    ErrorHandler:
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Workdays"
        Resume ErrorHandler_Exit
    
    End Sub

  3. #18
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,827
    just so you know, .value is the default property for a combo or textbox. You don't have to use it in code if you want to save some typing.
    Thanks for posting the solution.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-06-2016, 10:28 AM
  2. Replies: 5
    Last Post: 12-16-2014, 10:01 AM
  3. Replies: 11
    Last Post: 09-16-2014, 05:48 AM
  4. Replies: 6
    Last Post: 04-28-2014, 06:48 AM
  5. Replies: 3
    Last Post: 04-20-2012, 01:30 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