I have a listbox from where I select records, I enter the data and then update the table with the data entered.
It runs through without any errors, getting the message "All Medical Details Inserted" but none of the data have been written to the table.
Anyone who can see what I do wrong?
Is there a better way to do this?
Any help will be highly appreciated!
It runs through without any errors, getting the message "All Medical Details Inserted" but none of the data have been written to the table.
Anyone who can see what I do wrong?
Is there a better way to do this?
Any help will be highly appreciated!
Code:
Private Sub cmdInsert_Click()
If Me.Dirty Then Me.Dirty = False 'This line Saves the Data just entered
Dim rnSQL As String
Dim varItem As Variant
Dim lngTreatmentID As Long
Dim lngTreatmentTypeID As Long
Dim dteTreatmentDate As Date
Dim lngVetID As Long
Dim strWeight As String
Dim dteFollowUpDate As Date
Dim lngTreatedByID As Long
Dim strAssessment As String
lngTreatmentID = Me.txtTreatmentID
lngTreatmentTypeID = Me.txtTreatmentTypeID
dteTreatmentDate = Me.TreatmentDate
lngVetID = Nz(Me.txtVetID, 0)
strWeight = Nz(Me.txtWeight, 0)
dteFollowUpDate = Nz(Me.txtFollowUpDate, 0)
lngTreatedByID = Me.txtTreatedByID
strAssessment = Nz(Me.txtAssessment, 0)
For Each varItem In Me.lstPuppies.ItemsSelected
varItem = Me.lstPuppies.Column(0, varItem)
rnSQL = "INSERT INTO tblMedicalTreatments (DogID, TreatmentID, TreatmentTypeID, TreatmentDate, VetID, Weight, FollowupDate, TreatedByID, Assessment)" _
& " Values ( " & varItem & ", " & Me.txtTreatmentID & "," & Me.txtTreatmentTypeID & "," & Format(Me.TreatmentDate, "\#dd\-mmm\-yyyy\#") & " , " _
& IIf(IsNull(txtVetID), "Null", txtVetID) & ",'" & IIf(IsNull(txtWeight), "Null", txtWeight) & "', " & Format(Me.txtFollowUpDate, "\#dd\-mmm\-yyyy\#") & " , " _
& Me.txtTreatedByID & ",'" & IIf(IsNull(txtAssessment), "Null", txtAssessment) & "' )"
Debug.Print rnSQL
CurrentDb.Execute rnSQL
Next varItem
MsgBox "All Medical Details Inserted", vbInformation
End Sub