This code keeps generating the error message "Data type mismatch." Can you see anything blatently wrong here? I can't seem to get the SQL to work correctly. I have a feeling it's somewhere in the syntax, but I can't seem to find out exactly where.
Also can you set a string or int variable = to the value in a text box, like strMystring = Me!txtMytext.Value? - is this legal? Thanks in advance for help. See code below.
Private Sub cmdDeleteSelectedViolation_Click()
Dim frm As Form, ctl As Control
Dim varSelection As Variant
Dim intBuildingID As Integer
Dim strDeleteQuery As String
Set frm = Forms!frmViolations
Set ctl = frm!lstCurrentElectricalViolations
For Each varSelection In ctl.ItemsSelected
varSelection = ctl.Column(1)
intBuildingID = Me.txtBuildingID.Value
strDeleteQuery = "DELETE tblJunctionBuildingViolation.BuildingID, tblJunctionBuildingViolation.ViolationID FROM tblJunctionBuildingViolation WHERE (((tblJunctionBuildingViolation.BuildingID)='" & intBuildingID & "')AND ((tblJunctionBuildingViolation.ViolationID)='" & varSelection & "'));"
DoCmd.RunSQL (strDeleteQuery)
Next varSelection
Forms!frmViolations!.Refresh
End Sub
Also can you set a string or int variable = to the value in a text box, like strMystring = Me!txtMytext.Value? - is this legal? Thanks in advance for help. See code below.
Private Sub cmdDeleteSelectedViolation_Click()
Dim frm As Form, ctl As Control
Dim varSelection As Variant
Dim intBuildingID As Integer
Dim strDeleteQuery As String
Set frm = Forms!frmViolations
Set ctl = frm!lstCurrentElectricalViolations
For Each varSelection In ctl.ItemsSelected
varSelection = ctl.Column(1)
intBuildingID = Me.txtBuildingID.Value
strDeleteQuery = "DELETE tblJunctionBuildingViolation.BuildingID, tblJunctionBuildingViolation.ViolationID FROM tblJunctionBuildingViolation WHERE (((tblJunctionBuildingViolation.BuildingID)='" & intBuildingID & "')AND ((tblJunctionBuildingViolation.ViolationID)='" & varSelection & "'));"
DoCmd.RunSQL (strDeleteQuery)
Next varSelection
Forms!frmViolations!.Refresh
End Sub