Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Form load/initalise error

I have created a form which creates a combo box from another open file. If
that other file isn't open I want to be able to trap the error with a msgbox.
However I can't find a way of the form not being displayed (which results in
nothing in the combo box).

I hope this makes sense

Any ideas?

Many thanks

James
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Form load/initalise error

Hi James,

You can actually test if the workbook is open with the following code. I
have included the code to open the workbook if not already open so you can
please yourself if you want to use this method or just use the msgbox and
then Exit Sub.

Sub OpenWorkbook()
Dim strComboDataPath
Dim strComboDataWb As String
Dim wbComboData As Workbook

'Can edit ThisWorkbook.Path in the _
following line and use actual path _
enclosed in double quotes
strComboDataPath = ThisWorkbook.Path & "\"

strComboDataWb = "Combo Population Data.xlsm"

On Error Resume Next

Set wbComboData = Workbooks(strComboDataWb)

If Err.Number 0 Then 'Workbook not open
'MsgBox for testing only
MsgBox "Workbook " & strComboDataWb & " not open"

On Error GoTo 0 'Resume error trapping ASAP

'If required open the workbook as follows
Workbooks.Open Filename:= _
strComboDataPath & strComboDataWb

Set wbComboData = Workbooks(strComboDataWb)

End If

On Error GoTo 0 'Cancel resume next

'Your code to initialize userform and populate the combobox here

MsgBox wbComboData.Name 'for testing only

End Sub


--
Regards,

OssieMac


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Form load/initalise error

Thanks Ossie. Unfortunately I didn't explain myself clearly enough. I was
using the update combobox as an example. However what I really want to know
is how to stop a form from being displayed if there is a problem in the form
intialisaton.

Hope this makes sense

James

"OssieMac" wrote:

Hi James,

You can actually test if the workbook is open with the following code. I
have included the code to open the workbook if not already open so you can
please yourself if you want to use this method or just use the msgbox and
then Exit Sub.

Sub OpenWorkbook()
Dim strComboDataPath
Dim strComboDataWb As String
Dim wbComboData As Workbook

'Can edit ThisWorkbook.Path in the _
following line and use actual path _
enclosed in double quotes
strComboDataPath = ThisWorkbook.Path & "\"

strComboDataWb = "Combo Population Data.xlsm"

On Error Resume Next

Set wbComboData = Workbooks(strComboDataWb)

If Err.Number 0 Then 'Workbook not open
'MsgBox for testing only
MsgBox "Workbook " & strComboDataWb & " not open"

On Error GoTo 0 'Resume error trapping ASAP

'If required open the workbook as follows
Workbooks.Open Filename:= _
strComboDataPath & strComboDataWb

Set wbComboData = Workbooks(strComboDataWb)

End If

On Error GoTo 0 'Cancel resume next

'Your code to initialize userform and populate the combobox here

MsgBox wbComboData.Name 'for testing only

End Sub


--
Regards,

OssieMac


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Form load/initalise error

Hi James,

If it produces an error then you can trap that otherwise need to know
exactly what is supposed to be on the form and go through the exercise of
testing each control and to do that one needs all of the info regarding the
controls.

--
Regards,

OssieMac


"James Price at Premier" wrote:

Thanks Ossie. Unfortunately I didn't explain myself clearly enough. I was
using the update combobox as an example. However what I really want to know
is how to stop a form from being displayed if there is a problem in the form
intialisaton.

Hope this makes sense

James

"OssieMac" wrote:

Hi James,

You can actually test if the workbook is open with the following code. I
have included the code to open the workbook if not already open so you can
please yourself if you want to use this method or just use the msgbox and
then Exit Sub.

Sub OpenWorkbook()
Dim strComboDataPath
Dim strComboDataWb As String
Dim wbComboData As Workbook

'Can edit ThisWorkbook.Path in the _
following line and use actual path _
enclosed in double quotes
strComboDataPath = ThisWorkbook.Path & "\"

strComboDataWb = "Combo Population Data.xlsm"

On Error Resume Next

Set wbComboData = Workbooks(strComboDataWb)

If Err.Number 0 Then 'Workbook not open
'MsgBox for testing only
MsgBox "Workbook " & strComboDataWb & " not open"

On Error GoTo 0 'Resume error trapping ASAP

'If required open the workbook as follows
Workbooks.Open Filename:= _
strComboDataPath & strComboDataWb

Set wbComboData = Workbooks(strComboDataWb)

End If

On Error GoTo 0 'Cancel resume next

'Your code to initialize userform and populate the combobox here

MsgBox wbComboData.Name 'for testing only

End Sub


--
Regards,

OssieMac


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Form load/initalise error

OssieMac

Does that mean that I can't unload a form during initialisation?

Many thanks

James

"OssieMac" wrote:

Hi James,

If it produces an error then you can trap that otherwise need to know
exactly what is supposed to be on the form and go through the exercise of
testing each control and to do that one needs all of the info regarding the
controls.

--
Regards,

OssieMac


"James Price at Premier" wrote:

Thanks Ossie. Unfortunately I didn't explain myself clearly enough. I was
using the update combobox as an example. However what I really want to know
is how to stop a form from being displayed if there is a problem in the form
intialisaton.

Hope this makes sense

James

"OssieMac" wrote:

Hi James,

You can actually test if the workbook is open with the following code. I
have included the code to open the workbook if not already open so you can
please yourself if you want to use this method or just use the msgbox and
then Exit Sub.

Sub OpenWorkbook()
Dim strComboDataPath
Dim strComboDataWb As String
Dim wbComboData As Workbook

'Can edit ThisWorkbook.Path in the _
following line and use actual path _
enclosed in double quotes
strComboDataPath = ThisWorkbook.Path & "\"

strComboDataWb = "Combo Population Data.xlsm"

On Error Resume Next

Set wbComboData = Workbooks(strComboDataWb)

If Err.Number 0 Then 'Workbook not open
'MsgBox for testing only
MsgBox "Workbook " & strComboDataWb & " not open"

On Error GoTo 0 'Resume error trapping ASAP

'If required open the workbook as follows
Workbooks.Open Filename:= _
strComboDataPath & strComboDataWb

Set wbComboData = Workbooks(strComboDataWb)

End If

On Error GoTo 0 'Cancel resume next

'Your code to initialize userform and populate the combobox here

MsgBox wbComboData.Name 'for testing only

End Sub


--
Regards,

OssieMac




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Form load/initalise error

James

If there is an error in the form's initialization then it won't show
it'll just, well, error.

I think you might have problems unloading a form during
initialization, why would you want to do that anyway?

Why not check whatever you need to check, eg if the other workbook is
open, before you open the form?

By the way I tried unloading a form in it's initialize event and all
sorts of error trapping - nothing worked.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Form load/initalise error

Thanks Norie

You're riight I was trying to be lazy and do the checking on
initialisation. The error messages are quite odd though

Cheers



"norie" wrote:

James

If there is an error in the form's initialization then it won't show
it'll just, well, error.

I think you might have problems unloading a form during
initialization, why would you want to do that anyway?

Why not check whatever you need to check, eg if the other workbook is
open, before you open the form?

By the way I tried unloading a form in it's initialize event and all
sorts of error trapping - nothing worked.

.

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
User Form - how to load it Balan Excel Discussion (Misc queries) 4 May 20th 08 12:39 PM
Load user form?? Mekinnik Excel Programming 1 October 5th 07 10:13 PM
Load form when workbook opens anna Excel Programming 2 August 2nd 06 11:22 PM
Load multiple image with same form MIKE Excel Programming 2 February 12th 06 09:57 PM
Load and Unload Form commands R Avery Excel Programming 4 July 29th 04 03:16 PM


All times are GMT +1. The time now is 01:26 PM.

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"