I have 2 fields and 2 listboxes not writing to tbl from the form. The 2 fields are getting data but not the correct data. I am not sure what is causing it.
I have code for the muti-select listboxes but the selections are not writing to the table. I was wondering if someone could take a look at the code and see what I am missing.
Code:
Private Sub cmdAddVAC_Click()
Dim varItem As Variant 'Selected items
Dim strDelim As String 'Delimiter for this field type.
Dim i As Variant
Dim rst As DAO.Recordset
Dim ctl As Control
Dim db As DAO.Database
Dim strCriteria As String
Set rst = CurrentDb.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"
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
End If
Dim issuesValue As String, vacancyValue As String
Dim i As Variant
For Each i In Me.lstContractorIssues.ItemsSelected
issuesValue = issuesValue & ", " & Me.lstContractorIssues.ItemData(i)
Next i
For Each i In Me.lstVacancyReason.ItemsSelected
vacancyValue = vacancyValue & ", " & Me.lstVacancyReason.ItemData(i)
Next i
Me.lstContractorIssues = Right(issuesValue, Len(issuesValue) - 1)
Me.lstVacancyReason = Right(vacancyValue, Len(vacancyValue) - 1)
'All the fields are writing correctly to the table but the Contract Number,CLIN the 2 listboxes (ContractorIssues lstContractorIssues) (VACReason lstVacancyReason)
.AddNew
.Fields("Analyst") = cboAnalyst.Value
.Fields("ReportDate") = txtReportDate.Value
.Fields("ContractNumber") = cboContractNumber.Value 'This is writing the Contractor Name instead of the Contract Number
.Fields("Contractor") = txtContractor.Value
.Fields("MATO") = txtMATO.Value
.Fields("ContractorOnset") = txtContractorOnset.Value
.Fields("ContractorResolved") = txtContractorResolved.Value
.Fields("ContractorComments") = txtContractorComments.Value
.Fields("ContractorIssues") = lstContractorIssues.Value
.Fields("VACTO") = cboTOvac.Value
.Fields("VACCLIN") = cboCLINvac.Value 'This is writing the Contract Number instead of the CLIN
.Fields("VACCOR") = txtCORVAC.Value
.Fields("VACMTF") = txtMTFVAC.Value
.Fields("VACLabor") = txtLaborvac.Value
.Fields("VACSite") = txtSiteVAC.Value
.Fields("VACClinic") = txtClinicalVAC.Value
.Fields("VACIndcov") = txtIndCovVAC.Value
.Fields("MissedHours") = txtIndHours.Value
.Fields("MissedShifts") = txtCovHours.Value
.Fields("TOStart") = txtTOStart.Value
.Fields("TOEnd") = txtTOEnd.Value
.Fields("VACFrom") = txtVacFrom.Value
.Fields("VACTo") = txtVacTo.Value
.Fields("VACReason") = lstVacancyReason.Value
.Fields("VACComments") = txtVACComments.Value
.Update
Set rst = Nothing
End Sub
Private Sub cboContractNumber_Click()
Me.cboContractNumber = Me.cboContractNumber.Column(0)
Me.txtContractor = Me.cboContractNumber.Column(1)
Me.txtMATO = Me.cboContractNumber.Column(2)
Me.cboTOvac.Requery
Me.cboCLINvac.Requery
'Me.cboTOHCW.Value = ""
'Me.cboTOCDR.Value = ""
'Me.cboTOTERM.Value = ""
End Sub
Private Sub cboTOVAC_Click()
Me.txtTOStart = Me.cboTOvac.Column(1)
Me.txtTOEnd = Me.cboTOvac.Column(2)
Me.txtMTFVAC = Me.cboTOvac.Column(3)
Me.txtCORVAC = Me.cboTOvac.Column(4)
Me.cboCLINvac.Requery
End Sub
Private Sub cboCLINvac_Click()
Me.txtLaborvac = Me.cboCLINvac.Column(3)
Me.txtSiteVAC = Me.cboCLINvac.Column(4)
Me.txtClinicalVAC = Me.cboCLINvac.Column(5)
Me.txtIndVAC = Me.cboCLINvac.Column(6)
End Sub