When form control is empty (1 Viewer)

Christopherusly

Village Idiot.
Local time
Today, 04:56
Joined
Jan 16, 2005
Messages
81
I have two drop down menus on a form which are used to select a special date range (using sap week numbering) they are called:

Combo86
Combo88


these values are used in a query which is run when a user selects a report.

The question is, how do i alert the stupid user who is trying to run a report from a button that they have not selected a date range i.e. the date range is null, or nothing has been selected, in english this would be - open form, check date range, oh its empty, tell the user, cancel report load.

Any suggestions guys ...

Many thanks

Christophe.
 

Christopherusly

Village Idiot.
Local time
Today, 04:56
Joined
Jan 16, 2005
Messages
81
Code:
Private Sub reportpreview_Click()
On Error GoTo Err_reportpreview_Click

    Dim stDocName As String

    stDocName = "qry_costs"
    DoCmd.OpenReport stDocName, acPreview

Exit_reportpreview_Click:
    Exit Sub

Err_reportpreview_Click:
    MsgBox Err.Description
    Resume Exit_reportpreview_Click
    
End Sub

is what i have so far.
 

Yarp

Registered User.
Local time
Today, 04:56
Joined
Sep 16, 2009
Messages
51
before you run your query, check the values. Something like:

Code:
If Me.Combo86.Value = "" Or Me.Combo88.Value = "" Then
     Msgbox "You are a stupid user"
Else
     Your code here to run query
End If

I am assuming you are running the code from the form and that Combo86 and Combo88 are null when the form opens.
 

Christopherusly

Village Idiot.
Local time
Today, 04:56
Joined
Jan 16, 2005
Messages
81
thanks Yarp, when i try that it still loads the report if the combos have any value or not.

Code:
Private Sub reportpreview_Click()
On Error GoTo Err_reportpreview_Click

If Me.Combo86.Value = " " Or Me.Combo88.Value = " " Then
     MsgBox "You are a stupid user"
Else
    Dim stDocName As String
    stDocName = "qry_costs"
    DoCmd.OpenReport stDocName, acPreview
    
End If
Exit_reportpreview_Click:
    Exit Sub

Err_reportpreview_Click:
    MsgBox Err.Description
    Resume Exit_reportpreview_Click
    
End Sub

this is what my code now looks like ... any more suggestions, are quite welcome :)
 

Christopherusly

Village Idiot.
Local time
Today, 04:56
Joined
Jan 16, 2005
Messages
81
ahhh however if i set the default values to "" then it works :) and my user is suitably abused :) thank you yarp :) adds kudos.
 

Yarp

Registered User.
Local time
Today, 04:56
Joined
Sep 16, 2009
Messages
51
This is more a tip, and a personal preference, so feel free to ignore me!!

I prefer not to call my combo's Combo86 (for example). I will change the name to comboStartDate. It makes it much easier to debug or alter your code at a later date, and also for others to follow your code if alterations are made further down the line. I.E. no need to search the form to find which combo is Combo86, it should be obvious from the name.

Sorry if this sounds like teaching you to suck eggs, but it is something I have not been good at in the past and it has created issues!
 
Last edited:

Christopherusly

Village Idiot.
Local time
Today, 04:56
Joined
Jan 16, 2005
Messages
81
no not at all, its my own bad habit :) this is why i doodle on screen shots of my forms and the like whilst working on them :) i like to be awkward and not have people fiddle, and there are quite a few fiddlers in my office i can tell you ! thanks for your help :)

Christophe
 

Users who are viewing this thread

Top Bottom