Hi! I have a little problem... I have a main form with a subform control that is used to display several subforms (there are buttons on the main form used to switch which subform is currently displayed). In order to save/cancel the changes made in the subform, I made a Save button (how original!) on the MAIN form. Here's the code I use in each subform:
In the subform's OnLoad event:
In the subform's Save function:
In the subform's OnUnload event:
In the MAIN FORM's Save button's click event:
Everything here works fine. I have a Quit button on my main form with this code:
The problem is that when I click this button, I get an error message saying "Incompatible type" (the error is called from the subform's OnUnload event). But when I click the X in the app's title bar, I don't get this error message... What's the problem? Any help would be much appreciated!
In the subform's OnLoad event:
Code:
ReDim mvarFields(0 To (Me.Recordset.Fields.Count - 1))
mblnError = False
Call Save
In the subform's Save function:
Code:
Dim f As Field, i As Integer
i = 0
For Each f In Me.Recordset.Fields
If f.Name <> "CustomerID" Then
mvarFields(i) = f.Value
i = i + 1
End If
Next f
In the subform's OnUnload event:
Code:
Dim rs As Recordset
Set rs = Me.Recordset
rs.Edit
Dim f As Field, i As Integer
i = 0
For Each f In Me.Recordset.Fields
If f.Name <> "CustomerID" Then
f.Value = mvarFields(i)
i = i + 1
End If
Next f
rs.Update
Set rs = Nothing
In the MAIN FORM's Save button's click event:
Code:
' | this is a custom
' v validation function
If sfSubForm.Form.Validation = True Then
Call sfSubForm.Form.Save
MsgBox "Data saved with success!"
End If
Everything here works fine. I have a Quit button on my main form with this code:
Code:
DoCmd.Quit