View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Stevie_mac Stevie_mac is offline
external usenet poster
 
Posts: 39
Default Closing user form in Initialize macro?

There is 2 things you can do...

1. Move your code to UserForm_Activate. If an error occurs, you can unload in there.
or
2. Move your code to a Module & if the Access query succeeds, show the form, if not, show the error.

Example of No 2...

Sub LoadDataForm()
Dim f As frmData
Set f = New frmData
If f.GetAccessData() = True Then
f.Show
Else
MsgBox f.GetLastError() 'you'd have to add this!
End If
Set f = Nothing
End Sub



"Don Wiss" wrote in message ...
I have a situation where the user form Initialize routine can fail to
retrieve data from Access (which is used to populate a combo box). I now
display a msgbox, but I then have to display the form, which of course is
non-functional. I tried using Unload Me, but it didn't work. Presumably
as the form wasn't yet loaded. I would think there must be a way to abort
an initialization and not display the form.

Don <www.donwiss.com (e-mail link at home page bottom).