I have a form for entering tire change records that has been working fine for several years.
There are two records created for each tire change, one for the tire that was removed and another for the tire that was installed.
There is also SQL to update the tires table with the current status of the tire(Discarded, In Service, etc.).
Now when I try to enter tire change records I get an error message "Update Tires 2015 You can't go to the specified record". This occurs after the "removal" record is created and the code calls for a new record for the "install".
Upon trying to exit the error message appears "You cannot add or change a record because a related record is required in "tblTires".
The tires are in the table since they are selected from a series of combo boxes based on the tires table. These combos are on a dialog form which when completed is hidden and the variables are defined from this form.
Here is the code I have:
This is where the code fails.
Below is the code for the "new tire install" record.
Thanks for your assistance!
Knowlton
There are two records created for each tire change, one for the tire that was removed and another for the tire that was installed.
There is also SQL to update the tires table with the current status of the tire(Discarded, In Service, etc.).
Now when I try to enter tire change records I get an error message "Update Tires 2015 You can't go to the specified record". This occurs after the "removal" record is created and the code calls for a new record for the "install".
Upon trying to exit the error message appears "You cannot add or change a record because a related record is required in "tblTires".
The tires are in the table since they are selected from a series of combo boxes based on the tires table. These combos are on a dialog form which when completed is hidden and the variables are defined from this form.
Here is the code I have:
Code:
Case 1 'tire removed and discarded
If Not Me.NewRecord Then 'be sure you're at a new record
DoCmd.GoToRecord , , acNewRec
End If
If intOldTire <> 1 Then 'if there is a defined old tire
If dtOldTire < Forms!frmServices!ServiceDate Then
Dim strSQL As String 'set discard to true and InService to False for OldTire in the tires table
strSQL = _
"UPDATE tblTires " & _
"SET tblTires.Discarded = True, tblTires.InService = False " & _
"WHERE (((tblTires.TireID) =" & intOldTire & "));"
CurrentDb.Execute strSQL, dbFailOnError
End If
With Me
.txtUpdatedTire = intOldTire 'set tire ID for this record
.txtUpdatedTirePosition = intOldPosition 'set position for this record
.txtAction = "Removed" 'set status as removed
.txtTreadDepth = intDiscardDepth 'set tread depth
.Notes = Forms!frmUpdateTireLocation!txtNotesOldTire
End With
DoCmd.GoToRecord , , acNewRec 'move to new record
End If
Below is the code for the "new tire install" record.
Code:
With Me
.txtUpdatedTire = intNewTire 'set tire ID for this record
.txtUpdatedTirePosition = intOldPosition 'set position for this record
.txtAction = "Installed" 'set status as installed
.Notes = Forms!frmUpdateTireLocation!txtNotesNewTire
End With
If dtNewTire < Forms!frmServices!ServiceDate _
Or dtNewTire = 0 Then 'there are no service records at a later date
Dim strInService As String 'set New Tire InService to True
strInService = _
"UPDATE tblTires " & _
"SET tblTires.InService = True, tblTires.Discarded = False " & _
"WHERE (((tblTires.TireID) =" & intNewTire & "));"
CurrentDb.Execute strInService, dbFailOnError
DoCmd.GoToRecord , , acNewRec 'move to new record
End If
Knowlton
Comment