|
-
Apr 12th, 2004, 09:47 AM
#1
Thread Starter
Addicted Member
MsgBox - Unload Form Predicament
Okay, I have the following code in my Form_Load
Code:
If datanavigator.Recordset.RecordCount = 0 Then
MsgBox "There are No Invoices to be Viewed/Printed!", vbCritical, "No Records"
If vbOK = True Then
Unload Me
End If
End If
So it basically checks if the ADO (datanavigator) is empty and if it is, it brings up the message box, and when the person clicks Ok, it unloads the form, but here is the problem.
Using the code above, when the person clicks the ok, the message box stays there regardless of how many times u press ok and the app crashes.
How can I upload the form?
-
Apr 12th, 2004, 09:55 AM
#2
Fanatic Member
it should work if you remove the inner if condition - just let them click OK and then unload the form.
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
-
Apr 12th, 2004, 09:57 AM
#3
Fanatic Member
Try this instead
VB Code:
Call MsgBox("There are no invoices...", vbExclamation + vbDefaultButton1, "No records")
Unload Me
-
Apr 12th, 2004, 09:59 AM
#4
Thread Starter
Addicted Member
tried both ways - still dies!
-
Apr 12th, 2004, 10:02 AM
#5
Have you tried using just End?
VB Code:
If datanavigator.Recordset.RecordCount = 0 Then
MsgBox "There are No Invoices to be Viewed/Printed!", vbCritical, "No Records"
End
End If
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Apr 12th, 2004, 10:07 AM
#6
Thread Starter
Addicted Member
well at least with the "end" the app doesn't crash, but the whole app gets closed down, which is not what i want - btw the form in question is part of a mdiform, so i don't want the whole thing to get closed down!
-
Apr 12th, 2004, 10:14 AM
#7
Fanatic Member
It looks like the problem has more to do with closing the form that with handling the messagebox call. To see if this is right, place an empty MessageBox call in the Form_Unload event (MsgBox ""). If your app crashes after clicking the OK button of both boxes the problem lies with the unloading.
In that case, make sure you close everything: set all objects to nothing etc.
Author for Visual Basic Web Magazine
-
Apr 12th, 2004, 11:34 AM
#8
Thread Starter
Addicted Member
okay, i tried the thing in form_unload and it closed fine - no problems there!
-
Apr 12th, 2004, 11:59 AM
#9
Hmmm.... and I thought you can't unload a form in its load event. What I usually do is set a flag in the load event then unload the form in the activate event if the flag is true.
-
Apr 12th, 2004, 12:03 PM
#10
Thread Starter
Addicted Member
-
Apr 12th, 2004, 12:12 PM
#11
VB Code:
Private booForceUnload As Boolean 'module level
Private Sub Form_Load()
booForceUnlaod = False
If datanavigator.Recordset.RecordCount = 0 Then
If vbOK = MsgBox ("There are No Invoices to be Viewed/Printed!", vbCritical + vbOkOnly, "No Records") Then
booForceUnload = True
End If
End If
'
'
End Sub
Private Sub Form_Activate()
If booForceUnload = True Then
Unload Me
Exit Sub
End If
'
'
'
End Sub
Private Sub Form_Unload()
booForceUnload = False 'reset. just in case for succeeding form load
End Sub
Last edited by leinad31; Apr 12th, 2004 at 12:16 PM.
-
Apr 12th, 2004, 01:09 PM
#12
You can unload in the load event, it will just raise an error. One possible solution is to catch that error and exit the sub.
-
Apr 12th, 2004, 02:00 PM
#13
New Member
You could also check that condition before you allow the form to load. That would also look cleaner to the end user.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|