Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Programming for a Dynamic 'Where' clause

Hello

I have a form, which lets a user select a report and combo boxes to select
its criteria(s).

Example: "New Business Report" (State = 'NY', Region = North America)

Once a user selects the report and sets the criteria the 'Where' clause is
created dynamically in the code.

Example - In the code I have a series of statements which will check each
and every combo box. If the combo box is null it gets ignored, if it is
populated (State = NY) then the criteria is added to the 'Where' clause.

If Not IsNull(Me.cmb_Country) Then
strWhere = strWhere & "([Country] = """ & Me.cmb_Country
End If

I now want to add a date range as a criteria option. I don't
know how to write the syntax though.

My 2 combo boxes on the user form are cmb_StartDate & cmb_EndDate.

What is wrong with this syntax?
If Not IsNull(Me.cmb_StartDate) and IsNull (Me.cmb_EndDate) Then
strWhere = strWhere & "([Date] = between """ & Me.cmb_StartDate and
Me.cmb_EndDate.
End If

Any help would be much appreciated.

Thanks
AC

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Programming for a Dynamic 'Where' clause

See my reply in your original thread

Tim

--
Tim Williams
Palo Alto, CA


"ACase" wrote in message
...
Hello

I have a form, which lets a user select a report and combo boxes to select
its criteria(s).

Example: "New Business Report" (State = 'NY', Region = North America)

Once a user selects the report and sets the criteria the 'Where' clause is
created dynamically in the code.

Example - In the code I have a series of statements which will check each
and every combo box. If the combo box is null it gets ignored, if it is
populated (State = NY) then the criteria is added to the 'Where' clause.

If Not IsNull(Me.cmb_Country) Then
strWhere = strWhere & "([Country] = """ & Me.cmb_Country
End If

I now want to add a date range as a criteria option. I don't
know how to write the syntax though.

My 2 combo boxes on the user form are cmb_StartDate & cmb_EndDate.

What is wrong with this syntax?
If Not IsNull(Me.cmb_StartDate) and IsNull (Me.cmb_EndDate) Then
strWhere = strWhere & "([Date] = between """ & Me.cmb_StartDate and
Me.cmb_EndDate.
End If

Any help would be much appreciated.

Thanks
AC



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Programming for a Dynamic 'Where' clause


"Tim Williams" <timjwilliams at gmail dot com wrote in message
...
See my reply in your original thread

Tim


Which I don't see now, but it was something like

If Not IsNull(Me.cmb_StartDate) and not IsNull (Me.cmb_EndDate) Then
strWhere = strWhere & " ([Date] between '" & _
Me.cmb_StartDate & "' and '" & _
Me.cmb_EndDate & "') "
End If

You really need to tell us which database you're using, otherwise it's
diffcult to check the SQL syntax around the dates.

When you're done building the SQL string use debug.print and pate the
SQL into a query tool to check it.


Also - if possible - change that "Date" column name to something else.

Tim.



"ACase" wrote in message
...
Hello

I have a form, which lets a user select a report and combo boxes to
select
its criteria(s).

Example: "New Business Report" (State = 'NY', Region = North
America)

Once a user selects the report and sets the criteria the 'Where'
clause is
created dynamically in the code.

Example - In the code I have a series of statements which will
check each
and every combo box. If the combo box is null it gets ignored, if
it is
populated (State = NY) then the criteria is added to the 'Where'
clause.

If Not IsNull(Me.cmb_Country) Then
strWhere = strWhere & "([Country] = """ & Me.cmb_Country
End If

I now want to add a date range as a criteria option. I don't
know how to write the syntax though.

My 2 combo boxes on the user form are cmb_StartDate & cmb_EndDate.

What is wrong with this syntax?
If Not IsNull(Me.cmb_StartDate) and IsNull (Me.cmb_EndDate) Then
strWhere = strWhere & "([Date] = between """ & Me.cmb_StartDate
and
Me.cmb_EndDate.
End If

Any help would be much appreciated.

Thanks
AC





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PERCENTILE with an IF Clause Zeelotes Excel Worksheet Functions 3 April 19th 23 02:11 PM
IF Clause dpal Excel Worksheet Functions 8 July 19th 07 07:32 PM
"Between" in an IF clause gavin Excel Discussion (Misc queries) 5 May 2nd 05 09:27 PM
Creating/programming an Excel dynamic graph SeqZ Excel Programming 2 May 29th 04 03:12 PM
if then clause in a cell mikewild2000 Excel Programming 3 January 29th 04 04:35 PM


All times are GMT +1. The time now is 05:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"