Combining On_Load functions?

D

d9pierce

Hi,
I have started a db (new to access I may add) One my main form I have
the following code. This works very well witht he exception to the
second from the last private sub and I am working on that. I have on
this form a listbox populated by a qry. All works fine unil I try to
put the second section of code in it delivers a compile error. This
error is on the un_load and I was wondering if there is a way to
combine this code so both applications owrk? The first protects data
from being edited without confirmation and the second is code to allow
me to resize my columns on my list box? This second is also connected
to a module. Both functions work well separate, but not togeither.

Any Suggestions, PLEASE!

Option Compare Database
Option Explicit

Private boolFrmDirty As Boolean
Private boolFrmSaved As Boolean

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.Saved = False Then Me.Saved = (Status = acDeleteOK)
End Sub
Private Sub Form_AfterUpdate()
Me.Saved = True
End Sub

Private Sub Form_Delete(Cancel As Integer)
If Me.Dirtied = False Then DBEngine.BeginTrans
Me.Dirtied = True
End Sub
Private Sub Form_Dirty(Cancel As Integer)
If Me.Dirtied = False Then DBEngine.BeginTrans
Me.Dirtied = True
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database 'DAO
Dim rs As DAO.Recordset 'DOA
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Tbl_Contacts",
dbOpenDynaset)
Set Me.Recordset = rs
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim msg As Integer
If Me.Saved Then
msg = MsgBox("Do you want to commit all changes?", vbYesNoCancel)
Select Case msg
Case vbYes
DBEngine.CommitTrans
Case vbNo
DBEngine.Rollback
Case vbCancel
Cancel = True
End Select
Else
If Me.Dirtied Then DBEngine.Rollback
End If

End Sub
Public Property Get Dirtied() As Boolean
Dirtied = boolFrmDirty
End Property

Public Property Let Dirtied(boolFrmDirtyIn As Boolean)
boolFrmDirty = boolFrmDirtyIn
End Property

Public Property Get Saved() As Boolean
Saved = boolFrmSaved
End Property

Public Property Let Saved(boolFrmSavedIn As Boolean)
boolFrmSaved = boolFrmSavedIn
End Property

Private Sub List64_DblClick(Cancel As Integer)
DoCmd.OpenForm "Frm_Contact_Main", , , _
"ContactID = " = Me.List64

End Sub
Private Sub Form_Current()
Me.List64.Requery
End Sub

SECOND:

' Declare a var of type our Resizing class
Private ColReSize As clsResizeColumns


Private Sub Form_Load()
' Create a new instance of our class
Set ColReSize = New clsResizeColumns

' We must tell the Class which control
' we want to work with.
ColReSize.SetListBox Me.List4
' Turn on our flag to allow reszing
ColReSize.AllowResizing = True

' Set our Form size
DoCmd.MoveSize 0, 0, 7925, 5700
End Sub


Private Sub Form_Unload(Cancel As Integer)
' Release the reference to our class
Set ColReSize = Nothing
End Sub
 
G

George Nicholson

You can't have 2 procedures with the same name in a single module. You have
a Form_Unload event in both sections of your code and this is guaranteed to
raise an "ambiguous name" error. All you need to do is combine them: add
"Set ColReSize = Nothing" to your first Form_Unload and delete the 2nd one.
(You use Form_Open in one section and Form_Load in the 2nd, so that isn't a
problem. On that note, you could change one of your Form_Unloads to
Form_Close, rather than combining them, I suppose).

You've got a lot going on so its hard to say that will take care of all
problems, but it eliminates the most obvious compile error.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top