button asks for the field parameters when the value is null

  • Thread starter FilemakerPro_Developer
  • Start date
F

FilemakerPro_Developer

A button when clicked asks for the field parameters followup date and
mediation date when there are no records that have the criteria for today it
asks for the parameters so somewhere I need to allow for null values in this
script? Or do I add that in the fields on the form itself?
I tried adding IFF(not isnull([Followup DAte])) and I also even tried a
nested iff
BUT then the form didn't work.
thanks,


Private Sub cmdTickler_Click()
Dim strFilter As String
strFilter = "[FollowupDate]=#" & Format(VBA.Date, "mm/dd/yyyy") & "#"
strFilter2 = "[Mediation Date]=#" & Format(VBA.Date, "mm/dd/yyyy") & "#"

If Not Me.FilterOn Then
Me.Filter = strFilter & " or " & strFilter2
Me.FilterOn = True
Else
Me.FilterOn = False
End If
 
A

Albert D. Kallal

Are you allowing the query (or ms-access) to pop up the parameters prompts?

You likely should not do the above. (it too easy for the user to make a
mistake..and further, you loose control over what the user types in (they
might type in text, or numbers that don't make a date).

I would suggest that you consider building a prompt form:
Or do I add that in the fields on the form itself?

I usually put the "unbound" fields on the form.....

The user can then "enter" the Follow up date, or mediation date

or enter BOTH dates!!!

if isnull(me.txtFollowUpDate) = false then

strFilter = "FollowUpDate = #" & format(me.txtFollowUpDate,"mm/dd/yyyy")
& "#"

end if

if isnull(me.txtMediationDate) = false then

if strFilter <> "" then
strFilter = strFilter & " or "
end if

strFilter = strFilter & "MediationDate = " _
"#" & format(me.txtMediationDate,"mm/dd/yyyy") & "#"

end if

If Not Me.FilterOn Then
Me.Filter = strFilter
Me.FilterOn = True
Else
Me.FilterOn = False
End If

Notice how the code will allow one, two, or none in terms of parmatmers.

If you don't enter any date parmatmes, then all will show.....

--------------------------------

As you are finding out, putting forms! expression in queries can get really
messy real fast.

Even worse, is now that the query is now "married" and attached to that ONE
form. Often, I have a nice query that I could use MANY times for different
reports, and often even that same query could be used for reports...but then
someone comes along and puts in a expression that means the query is ONLY
good when that form is opened.

Worse, is very hard to control things like having 5 combo boxes, but the
user only selects restrictions in 3 of the combo boxes...and wants the other
2 to be ignore.

I could probably write another 10 or pages as to why putting forms
expressions in queries is bad (besides...it makes the queries real ugly, and
hard to read. and, the sql then is not standard anymore (it will not work
with server based systems either).

So, the solution use now is simply to take the values from the form, and
build your own where clause in code. That way, you simply design the reports
(or forms), and attached them to the query, BUT NO FORMS! conditions are
placed in the query.

To "send" the conditions to the report (or form), you simply use the "where"
clause. This is exactly why ms-access has this feature...and it solves a
zillion problems...and will reduce your development costs by a substantial
amount.

Take a look at the following screen shots to see what I mean:

http://www.members.shaw.ca/AlbertKallal/ridesrpt/ridesrpt.html

The code to make those above screens work and launch the report with the
selected restrictions when you hit the "print" button is easy:


dim strWhere as string

' select sales rep combo

if isnull(cboSalesRep) = false then

strWhere = "SalesRep = '" & cboSalesRep & "'"

end if

' select what City for the report

if isnull(cboCity) = false then
if strWhere <> "" then
strWhere = strWhere " and "
endif
strWhere = strWhere & "City = '" & cobCity & "'"
end if

Note how the 2nd combo test is setup. You can add as "many" more conditions
you want. Lets say we have a check box to only include Special Customers. We
can add to our very nice prompt screen a check box to

[x] Show Only Special customers

The code we add would be:

if chkSpeicalOnly = True then
if strWhere <> "" then
strWhere = strWhere " and "
endif
strWhere = strWhere & "SpecialCust = true"
endif

For sure, each combo and control we add to the nice report screen takes a
bit of code, but no more messy then the query builder..and this way, each
query is nice and clean, and free of a bunch of HIGHLY un-maintainable
forms! expressions.

Further, it means you can re-use the same query for different reports, and
have no worries about some form that is supposed to be open. So, a tiny bit
more code eliminates the messy query problem.. For me, this is very worth
while trade.
 
F

FilemakerPro_Developer

Albert
This was extremely helpful. I was wondering why the complications. I
almost completed my project and you et al helped get it done. I learned a
ton about Access. I got some of the recommended books and I will read them
over in time for my next one.
Janis
--
Janis


Albert D. Kallal said:
Are you allowing the query (or ms-access) to pop up the parameters prompts?

You likely should not do the above. (it too easy for the user to make a
mistake..and further, you loose control over what the user types in (they
might type in text, or numbers that don't make a date).

I would suggest that you consider building a prompt form:
Or do I add that in the fields on the form itself?

I usually put the "unbound" fields on the form.....

The user can then "enter" the Follow up date, or mediation date

or enter BOTH dates!!!

if isnull(me.txtFollowUpDate) = false then

strFilter = "FollowUpDate = #" & format(me.txtFollowUpDate,"mm/dd/yyyy")
& "#"

end if

if isnull(me.txtMediationDate) = false then

if strFilter <> "" then
strFilter = strFilter & " or "
end if

strFilter = strFilter & "MediationDate = " _
"#" & format(me.txtMediationDate,"mm/dd/yyyy") & "#"

end if

If Not Me.FilterOn Then
Me.Filter = strFilter
Me.FilterOn = True
Else
Me.FilterOn = False
End If

Notice how the code will allow one, two, or none in terms of parmatmers.

If you don't enter any date parmatmes, then all will show.....

--------------------------------

As you are finding out, putting forms! expression in queries can get really
messy real fast.

Even worse, is now that the query is now "married" and attached to that ONE
form. Often, I have a nice query that I could use MANY times for different
reports, and often even that same query could be used for reports...but then
someone comes along and puts in a expression that means the query is ONLY
good when that form is opened.

Worse, is very hard to control things like having 5 combo boxes, but the
user only selects restrictions in 3 of the combo boxes...and wants the other
2 to be ignore.

I could probably write another 10 or pages as to why putting forms
expressions in queries is bad (besides...it makes the queries real ugly, and
hard to read. and, the sql then is not standard anymore (it will not work
with server based systems either).

So, the solution use now is simply to take the values from the form, and
build your own where clause in code. That way, you simply design the reports
(or forms), and attached them to the query, BUT NO FORMS! conditions are
placed in the query.

To "send" the conditions to the report (or form), you simply use the "where"
clause. This is exactly why ms-access has this feature...and it solves a
zillion problems...and will reduce your development costs by a substantial
amount.

Take a look at the following screen shots to see what I mean:

http://www.members.shaw.ca/AlbertKallal/ridesrpt/ridesrpt.html

The code to make those above screens work and launch the report with the
selected restrictions when you hit the "print" button is easy:


dim strWhere as string

' select sales rep combo

if isnull(cboSalesRep) = false then

strWhere = "SalesRep = '" & cboSalesRep & "'"

end if

' select what City for the report

if isnull(cboCity) = false then
if strWhere <> "" then
strWhere = strWhere " and "
endif
strWhere = strWhere & "City = '" & cobCity & "'"
end if

Note how the 2nd combo test is setup. You can add as "many" more conditions
you want. Lets say we have a check box to only include Special Customers. We
can add to our very nice prompt screen a check box to

[x] Show Only Special customers

The code we add would be:

if chkSpeicalOnly = True then
if strWhere <> "" then
strWhere = strWhere " and "
endif
strWhere = strWhere & "SpecialCust = true"
endif

For sure, each combo and control we add to the nice report screen takes a
bit of code, but no more messy then the query builder..and this way, each
query is nice and clean, and free of a bunch of HIGHLY un-maintainable
forms! expressions.

Further, it means you can re-use the same query for different reports, and
have no worries about some form that is supposed to be open. So, a tiny bit
more code eliminates the messy query problem.. For me, this is very worth
while trade.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top