View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
James Price at Premier James Price at Premier is offline
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