Background
- Microsoft Access 2010 database.
- Subform control is a continuous form control.
- Each record in the continuous form has several controls (comboboxes, textboxes) and a delete button.
- The underlying data source for the subform is a temp table.
Desired Behavior
When the delete button is clicked for a record on the subform, the record should be deleted from the display, temp table, and another permanent table.
Note
Temp table is created by query using several permanent tables. Normally the structure would be different, however this particular solution required normalization and re-creation of a new wide temp table (similar to a SQL view) to handle manipulating all the data in one form (subform included).
Problem
Whenever the delete button is clicked the subroutine's code fails to properly populate any of the controls for the current record in the subform.
Code
Private Sub btnDelete_Click()
On Error GoTo Err_Handler
Dim Reply As Integer
Reply = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Species Delete")
'do the deletion for temp & underlying tables
If Reply = 6 Then
'delete the record in temp_table
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnings True
'do for @ Quadrat that has a SpeciesCover record
Dim i As Integer
Dim strControl As String
For i = 1 To QUADRATS_PER_TRANSECT
strControl = "tbxCoverID_Q" & i
'only delete existing records (these should have a Cover ID value)
If Me.Controls(strControl) > 0 Then
Dim sp As New CoverSpecies
With sp
.CoverID = Me.Controls(strControl)
.DeleteCoverRecord
End With
End If
Next
End If
Exit_Handler:
Exit Sub
Err_Handler:
Select Case Err.Number
Case Else
MsgBox "Error #" & Err.Number & ": " & Err.Description, vbCritical, _
"Error encountered (#" & Err.Number & " - btnDelete_Click[Cover form])"
End Select
Resume Exit_Handler
End Sub
Symptoms
The code runs properly, except controls in the subform's current record are always NULL
so the ID for the record needing deletion from the underlying table (not the temp) is never identified and that record is not deleted.