Solved

Common Dialog hands at MDI Child load

Posted on 2002-03-04
9
215 Views
Last Modified: 2010-08-05
**************************************
Test this I removed the Common Dialog and now the app does not hang. Any suggestions?
**************************************

Hello Experts.

My program is an ADO database application that starts as a MDI parent. It has a common dialog that lets the user select a file to open, (Access, .mdb). Once the db file has been chosen I set an instance of the MDIChild  with 'New' then set its dbFile$ to the dialog's filename.

The problem occurs when I load the MDIChild. The app hangs and when I try to end it or the IDE I get a "Porgram not responding error message and both the app and the IDE end.

If I add a break point at the MDIChild's Form_Load event everything seens to work when I step throught the code.

Also, in the MDIChild Form_Load I also set and load instance of a small status form. It lets the user see the status of tables beinng loaded, (status bar).

I think that I may not be instantiating the forms correctly, i.e. 'set oFrm = New frmJobs'; but why does this work when I use the break point?

Thanks, JP

0
Comment
Question by:jponce
  • 4
  • 4
9 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 6839355
can paste ur form load code?
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6839395
It sounds like you may have code under two events that are calling each other.  Sometimes, events fire in different orders when in the debugger versus when you are running compiled code.  

One thing to try is to put some debug.print or printer.print statements in some of the event procedures and then compile and run the EXE.  Use either Spyworks to view the debug output or in the case of the printer statements, just let it run or a couple of seconds and then kill the app. and hopefully you'll get a listing of any event procedures that may be firing.  So, if you see alternating events firing like:

cboCustomer_GotFocus()
txtDept_LostFocus()
txtDept_GotFocus()
cboCustomer_LostFocus()
cboCustomer_GotFocus()
txtDept_LostFocus()
...etc

Then you know that you have an infinite loop in your event procedurs.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6839404
also, make sure that you're not showing the small form using:

Dim x as New frmStatus

x.Show vbModal

as that will hang the load of your MDIChild form until the status is closed.  make sure that you are showing the status form as modeless.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:jponce
ID: 6839646
'***************************************************88
'MDIParent loading the MDIChild
Private Sub mnuOpen_Click()
    Dim lErrNumber      As Long
    Dim sErrSource      As String
    Dim sErrDescription As String
    Const PROCEDURE_NAME As String = "Open Jobs"
    On Error GoTo ERROR_HANDLER
    With diaOpenDB
        .fileName = "\\SSmfp01\Divisions\Engineering\SsmUtilDB\SSMunits.mdb"
        .Filter = "SSM Utils database (SSMunits.mdb)|SSMunits.mdb"
        .FilterIndex = 1
        .Flags = &H1000
        .DefaultExt = "mdb"
        .InitDir = "\\SSmfp01\Divisions\Engineering\SsmUtilDB"
        .DialogTitle = "SSM Utilities database"
        .ShowOpen
        If .fileName = "" Then Unload Me
        Set jobs = New frmJobs
        jobs.dbPath = .fileName
    End With
    load jobs
    jobs.SetFocus
    Exit Sub
   
TIDY_UP:
     On Error Resume Next
    Unload jobs
    Set jobs = Nothing

     ' Re-raise if we found an error
     If lErrNumber <> 0 Then
         On Error GoTo 0
         err.Raise lErrNumber, sErrSource, sErrDescription
     End If
Exit Sub

ERROR_HANDLER:
     lErrNumber = err.number
     sErrDescription = err.Description
     sErrSource = FormatErrorSource(err.Source, MODULE_NAME, _
     PROCEDURE_NAME)
     Resume TIDY_UP
   
End Sub
'***********************************************
'Here is the MDIChild Load routine
Dim sqlStr As String
    If App.PrevInstance Then Unload Me
    Me.Show
    Set status = New frmStatus
    status.Show
    status.setMax 29#
    status.setValue
    ' make the scrollable picture box bigger than the form
    picScroll.Move 0, 0, 1.4 * ScaleWidth, 1.9 * ScaleHeight
   
    'set the default MS access db path
    'dbPath = "\\SSmfp01\Divisions\Engineering\SsmUtilDB"
    'dbPath = "d:\work\working\working1\SsmUtilDB"
   
    status.incStatus "Establishing Connection"
    Set aConn = New ADODB.Connection
    Set lookupConn = New ADODB.Connection
    Set aComm = New ADODB.Command
    Set aRS = New ADODB.Recordset
   
    ' connect to the units database
    Call connectToDB(aConn, dbPath, ";", adUseClient)
    Call connectToDB(lookupConn, dbPath, ";", adUseClient, adModeReadWrite, adAsyncConnect)
   
    status.incStatus "Loading Locations Table ..."
    aRS.Open "SELECT * FROM tblLocations", aConn, adOpenDynamic, adLockPessimistic, adCmdText
    Set AdodcLocations.Recordset = aRS.Clone
    aRS.Requery
    aRS.Close
...
...
...
0
 

Author Comment

by:jponce
ID: 6839653
'***************************************************88
'MDIParent loading the MDIChild
Private Sub mnuOpen_Click()
    Dim lErrNumber      As Long
    Dim sErrSource      As String
    Dim sErrDescription As String
    Const PROCEDURE_NAME As String = "Open Jobs"
    On Error GoTo ERROR_HANDLER
    With diaOpenDB
        .fileName = "\\SSmfp01\Divisions\Engineering\SsmUtilDB\SSMunits.mdb"
        .Filter = "SSM Utils database (SSMunits.mdb)|SSMunits.mdb"
        .FilterIndex = 1
        .Flags = &H1000
        .DefaultExt = "mdb"
        .InitDir = "\\SSmfp01\Divisions\Engineering\SsmUtilDB"
        .DialogTitle = "SSM Utilities database"
        .ShowOpen
        If .fileName = "" Then Unload Me
        Set jobs = New frmJobs
        jobs.dbPath = .fileName
    End With
    load jobs
    jobs.SetFocus
    Exit Sub
   
TIDY_UP:
     On Error Resume Next
    Unload jobs
    Set jobs = Nothing

     ' Re-raise if we found an error
     If lErrNumber <> 0 Then
         On Error GoTo 0
         err.Raise lErrNumber, sErrSource, sErrDescription
     End If
Exit Sub

ERROR_HANDLER:
     lErrNumber = err.number
     sErrDescription = err.Description
     sErrSource = FormatErrorSource(err.Source, MODULE_NAME, _
     PROCEDURE_NAME)
     Resume TIDY_UP
   
End Sub
'***********************************************
'Here is the MDIChild Load routine
Dim sqlStr As String
    If App.PrevInstance Then Unload Me
    Me.Show
    Set status = New frmStatus
    status.Show
    status.setMax 29#
    status.setValue
    ' make the scrollable picture box bigger than the form
    picScroll.Move 0, 0, 1.4 * ScaleWidth, 1.9 * ScaleHeight
   
    'set the default MS access db path
    'dbPath = "\\SSmfp01\Divisions\Engineering\SsmUtilDB"
    'dbPath = "d:\work\working\working1\SsmUtilDB"
   
    status.incStatus "Establishing Connection"
    Set aConn = New ADODB.Connection
    Set lookupConn = New ADODB.Connection
    Set aComm = New ADODB.Command
    Set aRS = New ADODB.Recordset
   
    ' connect to the units database
    Call connectToDB(aConn, dbPath, ";", adUseClient)
    Call connectToDB(lookupConn, dbPath, ";", adUseClient, adModeReadWrite, adAsyncConnect)
   
    status.incStatus "Loading Locations Table ..."
    aRS.Open "SELECT * FROM tblLocations", aConn, adOpenDynamic, adLockPessimistic, adCmdText
    Set AdodcLocations.Recordset = aRS.Clone
    aRS.Requery
    aRS.Close
...
...
...
0
 
LVL 18

Accepted Solution

by:
mdougan earned 100 total points
ID: 6840095
Well, here are some immediate problems:

  If .fileName = "" Then Unload Me
   Set jobs = New frmJobs
   ' this code might actually load jobs
   jobs.dbPath = .fileName
   End With
   ' Now, you'd be loading it again, probably only hurts
   ' because you'll be executing form_load twice
   load jobs
   ' Normally, you would say jobs.Show, not Setfocus
   jobs.SetFocus
   Exit Sub

I'd change that code to this:


     If .fileName = "" Then Unload Me
     Set jobs = New frmJobs
     jobs.dbPath = .fileName
   End With
   jobs.Show
   Exit Sub

Now, I see you're doing the .show inside the form_load for jobs, I wouldn't do that there.  I'd do it in the main form like I have above.  Also, you have some problems in this form_load procedure:

' App.prevInstance isn't checking to see if the same form
' is already loaded.  This check should only be done in
' your main form, and only when your program first starts up
 If App.PrevInstance Then Unload Me
   Me.Show
   Set status = New frmStatus
' I'd move .Show after all property settings  
   status.Show
   status.setMax 29#
   status.setValue
   
So, I'd change the code to first delete the App.Previnstance and then delete the Me.Show.  And then change the rest of the code to the following:

   Set status = New frmStatus
   status.setMax 29#
   status.setValue
   status.Show


0
 

Author Comment

by:jponce
ID: 6842005
Thanks for the tips, this is close to what I originally had coded. Unfortunately the problem is still there. The app hangs when I run it, but runs fine when I place a break in the form_load.
I now believe the problem is caused by the common dialog. While testing I removed it and hard coded the file path. The app does not hang with this senario. Any other suggestions as to why I the common dialog can cause problems?

Thanks, JP
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6843139
The only thing I can see is you're using a UNC name for the initdir and filename.  Connecting to a network drive, even if it was mapped, could take a long time.  However, there is something about UNC names that they take a lot longer to resolve (particularly if you have a lot of nodes on your network).  Try commenting out those two things and see if your problem goes away.
0
 

Author Comment

by:jponce
ID: 6847536
Not a solution but you did help me to find the cause of the problem (Common Dialog).

Thanks all, JP
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question