Not Working

=TB=

Registered User.
Local time
Today, 15:00
Joined
Aug 13, 2002
Messages
68
I made some changes to a database I use in work while at home this weekend. Everything worked fine at Home but when I use the DB in work I am getting an error in the code I added.

Here is the code:

Private Sub Form_Load()

Dim intResponse As Integer
If DCount("SumOfQty", "qryPickLocation") < 1 Then

intResponse = MsgBox(" Sorry No Stock Available for the Item You Have Selected", vbInformation + vbOKOnly, "No Stock")
DoCmd.Close
[Form_Outgoing Transactions].Item_Number = ""

End If


End Sub


Can anyone throw some light on this for me.

Thankyou in advance.
 
Well, you could always say what the error you are getting is? ;)
 
Sorry I will expand a little

Basically it check to see if there are any results to displayed in the form, if there are not the form unloads and the message box pops up.. if there are results, the form opens and displays the results. All this worked fine.

Now what is happing is the form is opening regardless of whether there are results to display, then when I manualy close the form the message box pops up, once you click on the message box, the form - (if it has results to display) displays them, if there are no results it closes.

I have not altered this code at all from it working on my "Home" machine to using it at work. My level of DB programming is poor, I was wondering if it was a driver issue? or am I barking up the wrong tree.

Thanks in advance.
 
Okay, but I was asking for the specific error message.

Is this form open when your code runs?

Code:
[Form_Outgoing Transactions].Item_Number = ""


Also, don't put that in the Form_Load event, put this in the Form_open event:

Code:
    If DCount("SumOfQty", "qryPickLocation") < 1 Then
        MsgBox "Sorry No Stock Available for the Item You Have Selected", _
            vbInformation + vbOKOnly, "No Stock"
        Cancel = True
    End If
 
The error message is

Run Time Error 2501:
Close Action Was Cancelled

Is this form open when your code runs?


code:--------------------------------------------------------------------------------[Form_Outgoing Transactions].Item_Number = ""--------------------------------------------------------------------------------

Yes.

Moved the code to the on Open Event and that seems to work...

Thankyou very much for all your help
 
DCount is slow, you could replace it with

If (RecordsetClone.RecordCount = 0) Then
DoCmd.Close
Beep
MsgBox "Sorry No Stock Available for the Item You Have Selected", vbInformation, "No Stock Available"
End If

In the OnOpen event of your form
 
Yes this also works well, thankyou.
 

Users who are viewing this thread

Back
Top Bottom