Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with DoCmd.Quit

Status
Not open for further replies.

xezekielx

IS-IT--Management
Jun 30, 2005
93
CA
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:
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
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!
 
I had a similar issue...
My solution was to remove the MS Access X to close the MS Access Window and the X on the Main Menu. The code the remove the application close was a little difficult, but luckily I found what I needed on the I*Net.

Steve Medvid
&quot;IT Consultant & Web Master&quot;

Chester County, PA Residents
Please Show Your Support...
 
Well like I said in my first post, the X in the app's title bar doesn't cause any error so I don't see the point of removing it... I only get an error message when I use the Quit button on my main form
 
xezekielx,

On which line does your code break?

Ken S.
 
it broke on this line in the subform's OnUnload event:
Code:
f.Value = mvarFields(i)
. while debugging, I realised that the array mvarFields was empty (for some reason), so I just put this in the sub:
Code:
If Not IsEmpty(mvarFields) Then
   [...]
End If

It seems to work now! :) Thanks to all of you for helping!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top