Using Debug.Print shows that the value of x (AgencyID) is correct but that Me.InternalIncidentID has no value i.e. it doesn't print anything for it.
Using Debug.Print shows that the value of x (AgencyID) is correct but that Me.InternalIncidentID has no value i.e. it doesn't print anything for it.
You have defined x as an Integer but you are comparing it to True which is any non zero value. Is that what you want?Code:Dim x As Integer x = [Forms]![frmNewMain]![Combo573] If x = True Then
Yes, that should be fine. I want it to write to the table when something is filled in, so True should work for my needs.
Have you single stepped your code. Does it execute the Update query? Have you tried to create a new query that is just a SELECT query with the same criteria and see if any record qualifies?
New queries work, but I'm not sure how I would SELECT for the Me.InternalIncidentID value. It's not seeing the value for some reason, maybe the way my form is constructed. From what I can tell, it isn't executing because it needs the InternalIncidentID in order to write to the composite PK, and it's not getting it for some reason so it doesn't write.
Try this code:
Code:Private Sub Combo573_AfterUpdate() On Error GoTo Combo573Error Dim x As Integer x = [Forms]![frmNewMain]![Combo573] If x = True Then ' CurrentDb.Execute "INSERT INTO tblAgencyIncident(InternalIncidentID, AgencyID) Values (" & Me.InternalIncidentID & ", 'x');", dbFailOnError MsgBox "Going to excute the SELECT query!" CurrentDb.Execute "Select * From tblAgencyIncident " & _ "WHERE InternalIncidentID = " & Me.InternalIncidentID & " and AgencyID = 'x'" Else CurrentDb.Execute "DELETE FROM tblAgencyIncident WHERE InternalIncidentID = '" & Me.InternalIncidentID & "' AND AgencyID = 'x'", dbFailOnError End If ExitCombo573: Exit Sub Combo573Error: MsgBox Err & ": " & vbCrLf & Err.Description Resume ExitCombo573 End Sub
No error showing with the new code, still no write. This seems odd that I wouldn't get any error or message box.
Did the MsgBox pop up?
No, no message box came up
So it never even tried to execute the Select query. Do you know how to single step the code? I think that is next.
No unfortunately I don't know how to do that
When you are looking at the posted code, put your cursor to the left of the margin and click. It will put a dot there which is a breakpoint and the code will stop executing at that line. I would put the breakpoint at the " x = [Forms]![frmNewMain]![Combo573]" line. you can then use the F8 key to single step the code. If you hover over a variable the debugger will display it's value and the highlighting will show you the line of code that is executing.
Any luck? It should be pretty easy.
It lets me put the breakpoint in but when I hit F8 or select step into it makes a noise and doesn't work. I've looked it up and made sure that the "Use Access special keys" option is selected (it hasn't worked either selected or unselected) but to no avail. This is strange
You need to run the program after putting in the breakpoint. when the code hits the breakpoint it will stop and put you back looking at the code.