Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Closing user form in Initialize macro?

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).
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Closing user form in Initialize macro?

Check for a valid connection (abiolity to retrieve) prior to initailizing the
form. If you are not going to be able to run the retrieve then dont run the
initialize...

HTH

"Don Wiss" wrote:

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).

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Closing user form in Initialize macro?

Couple of ways, but both flash the form unfortunately.

1) If the conditions is met in Initialize, set a variable. Test the
variable in Activate event, and if set, unload the form

2) Good old Ontime. If the condition is met set a timed procedure

Application.OnTime Now + TimeSerial(0, 0, 1), "UnloadForm"

And in a standard code module, create a procedure called UnloadForm that
unloads the form.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"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).



  #4   Report Post  
Posted to microsoft.public.excel.programming
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).



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Closing user form in Initialize macro?

Another possibility.

Load the userform. Check if the Combobox has any items (Combobox1.ListCount
0) and then proceed. appropriately.


something like

Load UserForm1
If UserForm1.ComboBox1.ListCount 0 Then
UserForm1.Show
Else
Unload UserForm1
End If

where the UserForm's Initialize event loads the combobox with MS Access
data.

worked for me.


"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).



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing Excel user form generates error Ken Warthen Excel Discussion (Misc queries) 0 October 10th 07 08:30 PM
How to: User Form to assign a user defined range to a macro variab TrevTrav Excel Programming 1 March 22nd 05 07:57 PM
Help w/ macro to run user form GMet Excel Programming 2 September 7th 04 07:12 PM
User Form activated by a macro mxleite Excel Programming 3 July 3rd 04 01:33 AM
need form to initialize without closing bruce forster Excel Programming 2 April 21st 04 11:57 PM


All times are GMT +1. The time now is 04:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"