PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Form_Load event that unloads the Form that is loading-VBForums
Results 1 to 4 of 4

Thread: Form_Load event that unloads the Form that is loading

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Location
    Miami, FL
    Posts
    20

    Form_Load event that unloads the Form that is loading

    Hello,

    Sorry about the strange Title. Here is the scenerio.

    On a Form_Load of a form that is launched from another form

    Code:
    Private Sub cmdShowBidForm_Click()
        frmJobBid.Show vbModeless
    End Sub
    the first thing that the form does is connect to a database, and load some comboboxes. BUT... if the connection to the Database fails or the recordset returns no values, I want to simply display a message "Error loading form due to ..." and then return to the previous form that initiated the call.

    I run into the following issue, and I would like to see what other people have done to handle similiar situations.

    here is the code that I am currently using to unload the form
    Code:
    Private Sub LoadQBCustomersJobs()
    Dim oRS As ADODB.Recordset
    Dim sSql As String
    
    sSql = "SELECT QBCustomerListID, QBName, QBJobFullName, QBJobParentListID FROM QBCustomers"
    
    Set oRS = LoadRS(sSql)
    If oRS Is Nothing Then
        MsgBox "No customers are in the database. exiting form."
        unload me
        Exit Sub
    End If
    
        oRS.MoveLast
        MsgBox oRS.RecordCount
        
        '---... load Combos etc
    End Sub
    thanks,


    Steve

  2. #2
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Form_Load event that unloads the Form that is loading

    You can make this subroutine to be public, so you can call this event from the 'parent' form (at the cmdShowBidForm_Click event). You can also convert this subroutine to be a Function and you can pass a Boolean value back to the caller.

    vb Code:
    1. Private Sub cmdShowBidForm_Click()
    2.     frmJobBid.Show
    3.     If Not frmJobBid.LoadQBCustomersJobs Then Unload frmJobBid
    4. End Sub
    5.  
    6. '/////// in the frmJobBid form...
    7.  
    8. Public Function LoadQBCustomersJobs() as Boolean
    9. '........
    10.  
    11. LoadQBCustomersJobs = True 'if this value wont get overwritten, the end of this function a True will be the response
    12.  
    13. If oRS Is Nothing Then
    14.     MsgBox "No customers are in the database. exiting form."
    15.     LoadQBCustomersJobs = False 'set the response to False
    16.     Exit Function 'now pass it back to the parent
    17. End If
    18.  
    19.  
    20. '........
    21. End Function

    This way the parent form will wait for the response of this function. If the response is true that means the process has been succeed, no need to unload the form, otherwise it will unload it as well.

    Hope it helps.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Location
    Miami, FL
    Posts
    20

    Re: Form_Load event that unloads the Form that is loading

    Jim,

    perfect. exactly what I was interested in seeing. I kept getting a no object error before, because as the form unloaded, it would fail the exit sub command.

    This makes perfect sense. Appreciate the quick answer.


    Steve

  4. #4
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Form_Load event that unloads the Form that is loading

    I'm glad it worked! If you found this workaround as a solution to the problem, please do us a favor, and click on the Thread Tools menu up there, and select Mark Thread Resolved to notify the others, that this issue has been resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width