473,394 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

OpenForm with Where Clause

I am trying to write an Open Form command in VBA with a where clause in it.

I need to be able to do two different where clauses:

1) With a between in it: i.e. Between Date1 and Date2 or Between Data1 and
Data2

2) With a Like in it: Like *data1* or Like *date1*

3) Or a statement with both Between and Like in it.

I do not know how to make these statements?

Please help...

Thanks in advance...

Mike
m charney at dunlap hospital dot org
Apr 3 '06 #1
8 6453
Check out the example code for Method 2 in this article:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

The code explains how to build the WhereCondition based on whichever boxes
have an entry. You do exactly the same thing for OpenForm as it explains for
OpenReport.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Charney" <no*****@everything.net> wrote in message
news:fX*****************@newssvr25.news.prodigy.ne t...
I am trying to write an Open Form command in VBA with a where clause in
it.

I need to be able to do two different where clauses:

1) With a between in it: i.e. Between Date1 and Date2 or Between Data1 and
Data2

2) With a Like in it: Like *data1* or Like *date1*

3) Or a statement with both Between and Like in it.

I do not know how to make these statements?

Apr 3 '06 #2
Thanks Allen,

That took care of the between condition I needed. Do you know anything about
the Like condition in the where clause?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Check out the example code for Method 2 in this article:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

The code explains how to build the WhereCondition based on whichever boxes
have an entry. You do exactly the same thing for OpenForm as it explains
for OpenReport.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Charney" <no*****@everything.net> wrote in message
news:fX*****************@newssvr25.news.prodigy.ne t...
I am trying to write an Open Form command in VBA with a where clause in
it.

I need to be able to do two different where clauses:

1) With a between in it: i.e. Between Date1 and Date2 or Between Data1
and Data2

2) With a Like in it: Like *data1* or Like *date1*

3) Or a statement with both Between and Like in it.

I do not know how to make these statements?


Apr 3 '06 #3
Use the Like operator with Text type fields (not dates or numbers.)

Text fields need quotes as delimiters.
Use * as the wildcard, or % if the back end is Sql Server.

Example:
Dim strWhere As String
If Not IsNull(Me.txtFindCity) Then
strWhere = "(City Like ""*" & Me.txtFindCity & "*"")"
End If

If you want an example of how to filter a form based on any combination of
unbound search controls on different types of fields, try:
http://allenbrowne.com/unlinked/Search2000.zip
The example requires Access 2000 or later. The code is documented, but there
is no explanatory article.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Charney" <no*****@everything.net> wrote in message
news:ol*****************@newssvr13.news.prodigy.co m...
Thanks Allen,

That took care of the between condition I needed. Do you know anything
about the Like condition in the where clause?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Check out the example code for Method 2 in this article:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

The code explains how to build the WhereCondition based on whichever
boxes have an entry. You do exactly the same thing for OpenForm as it
explains for OpenReport.

"Mike Charney" <no*****@everything.net> wrote in message
news:fX*****************@newssvr25.news.prodigy.ne t...
I am trying to write an Open Form command in VBA with a where clause in
it.

I need to be able to do two different where clauses:

1) With a between in it: i.e. Between Date1 and Date2 or Between Data1
and Data2

2) With a Like in it: Like *data1* or Like *date1*

3) Or a statement with both Between and Like in it.

I do not know how to make these statements?

Apr 4 '06 #4
So what happens if I have a text field with numbers in it? Can I use the
str( ) function to change the number to a string, and will it still search
on the filed?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Use the Like operator with Text type fields (not dates or numbers.)

Text fields need quotes as delimiters.
Use * as the wildcard, or % if the back end is Sql Server.

Example:
Dim strWhere As String
If Not IsNull(Me.txtFindCity) Then
strWhere = "(City Like ""*" & Me.txtFindCity & "*"")"
End If

If you want an example of how to filter a form based on any combination of
unbound search controls on different types of fields, try:
http://allenbrowne.com/unlinked/Search2000.zip
The example requires Access 2000 or later. The code is documented, but
there is no explanatory article.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Charney" <no*****@everything.net> wrote in message
news:ol*****************@newssvr13.news.prodigy.co m...
Thanks Allen,

That took care of the between condition I needed. Do you know anything
about the Like condition in the where clause?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Check out the example code for Method 2 in this article:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

The code explains how to build the WhereCondition based on whichever
boxes have an entry. You do exactly the same thing for OpenForm as it
explains for OpenReport.

"Mike Charney" <no*****@everything.net> wrote in message
news:fX*****************@newssvr25.news.prodigy.ne t...
I am trying to write an Open Form command in VBA with a where clause in
it.

I need to be able to do two different where clauses:

1) With a between in it: i.e. Between Date1 and Date2 or Between Data1
and Data2

2) With a Like in it: Like *data1* or Like *date1*

3) Or a statement with both Between and Like in it.

I do not know how to make these statements?


Apr 4 '06 #5
Matching numbers based on the string value of the digits is not generally
useful. For example:
Like "1*"
matches 1, 10, 11, ... 19, 100, 101, ...
which is not really a useful sequence of numbers.

Access will do it, but it is not normally a good design.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Charney" <no*****@everything.net> wrote in message
news:FZ*******************@newssvr29.news.prodigy. net...
So what happens if I have a text field with numbers in it? Can I use the
str( ) function to change the number to a string, and will it still search
on the filed?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Use the Like operator with Text type fields (not dates or numbers.)

Text fields need quotes as delimiters.
Use * as the wildcard, or % if the back end is Sql Server.

Example:
Dim strWhere As String
If Not IsNull(Me.txtFindCity) Then
strWhere = "(City Like ""*" & Me.txtFindCity & "*"")"
End If

If you want an example of how to filter a form based on any combination
of unbound search controls on different types of fields, try:
http://allenbrowne.com/unlinked/Search2000.zip
The example requires Access 2000 or later. The code is documented, but
there is no explanatory article.

"Mike Charney" <no*****@everything.net> wrote in message
news:ol*****************@newssvr13.news.prodigy.co m...
Thanks Allen,

That took care of the between condition I needed. Do you know anything
about the Like condition in the where clause?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Check out the example code for Method 2 in this article:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

The code explains how to build the WhereCondition based on whichever
boxes have an entry. You do exactly the same thing for OpenForm as it
explains for OpenReport.

"Mike Charney" <no*****@everything.net> wrote in message
news:fX*****************@newssvr25.news.prodigy.ne t...
>I am trying to write an Open Form command in VBA with a where clause
>in it.
>
> I need to be able to do two different where clauses:
>
> 1) With a between in it: i.e. Between Date1 and Date2 or Between Data1
> and Data2
>
> 2) With a Like in it: Like *data1* or Like *date1*
>
> 3) Or a statement with both Between and Like in it.
>
> I do not know how to make these statements?

Apr 4 '06 #6
So how would I do a pattern match on a field that had data like DMH10257 or
DMH10096?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Matching numbers based on the string value of the digits is not generally
useful. For example:
Like "1*"
matches 1, 10, 11, ... 19, 100, 101, ...
which is not really a useful sequence of numbers.

Access will do it, but it is not normally a good design.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Charney" <no*****@everything.net> wrote in message
news:FZ*******************@newssvr29.news.prodigy. net...
So what happens if I have a text field with numbers in it? Can I use the
str( ) function to change the number to a string, and will it still
search on the filed?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Use the Like operator with Text type fields (not dates or numbers.)

Text fields need quotes as delimiters.
Use * as the wildcard, or % if the back end is Sql Server.

Example:
Dim strWhere As String
If Not IsNull(Me.txtFindCity) Then
strWhere = "(City Like ""*" & Me.txtFindCity & "*"")"
End If

If you want an example of how to filter a form based on any combination
of unbound search controls on different types of fields, try:
http://allenbrowne.com/unlinked/Search2000.zip
The example requires Access 2000 or later. The code is documented, but
there is no explanatory article.

"Mike Charney" <no*****@everything.net> wrote in message
news:ol*****************@newssvr13.news.prodigy.co m...
Thanks Allen,

That took care of the between condition I needed. Do you know anything
about the Like condition in the where clause?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
> Check out the example code for Method 2 in this article:
> Limiting a Report to a Date Range
> at:
> http://allenbrowne.com/casu-08.html
>
> The code explains how to build the WhereCondition based on whichever
> boxes have an entry. You do exactly the same thing for OpenForm as it
> explains for OpenReport.
>
> "Mike Charney" <no*****@everything.net> wrote in message
> news:fX*****************@newssvr25.news.prodigy.ne t...
>>I am trying to write an Open Form command in VBA with a where clause
>>in it.
>>
>> I need to be able to do two different where clauses:
>>
>> 1) With a between in it: i.e. Between Date1 and Date2 or Between
>> Data1 and Data2
>>
>> 2) With a Like in it: Like *data1* or Like *date1*
>>
>> 3) Or a statement with both Between and Like in it.
>>
>> I do not know how to make these statements?


Apr 4 '06 #7
If the field contains characters, it is not a Number type field.

If you are asking how to pattern match digits in specific places in a Text
field, use the # character.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Mike Charney" <no*****@everything.net> wrote in message
news:Gr****************@newssvr11.news.prodigy.com ...
So how would I do a pattern match on a field that had data like DMH10257
or DMH10096?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Matching numbers based on the string value of the digits is not generally
useful. For example:
Like "1*"
matches 1, 10, 11, ... 19, 100, 101, ...
which is not really a useful sequence of numbers.

Access will do it, but it is not normally a good design.

"Mike Charney" <no*****@everything.net> wrote in message
news:FZ*******************@newssvr29.news.prodigy. net...
So what happens if I have a text field with numbers in it? Can I use the
str( ) function to change the number to a string, and will it still
search on the filed?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Use the Like operator with Text type fields (not dates or numbers.)

Text fields need quotes as delimiters.
Use * as the wildcard, or % if the back end is Sql Server.

Example:
Dim strWhere As String
If Not IsNull(Me.txtFindCity) Then
strWhere = "(City Like ""*" & Me.txtFindCity & "*"")"
End If

If you want an example of how to filter a form based on any combination
of unbound search controls on different types of fields, try:
http://allenbrowne.com/unlinked/Search2000.zip
The example requires Access 2000 or later. The code is documented, but
there is no explanatory article.

"Mike Charney" <no*****@everything.net> wrote in message
news:ol*****************@newssvr13.news.prodigy.co m...
> Thanks Allen,
>
> That took care of the between condition I needed. Do you know anything
> about the Like condition in the where clause?
>
> Mike
>
> "Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
> news:44**********************@per-qv1-newsreader-01.iinet.net.au...
>> Check out the example code for Method 2 in this article:
>> Limiting a Report to a Date Range
>> at:
>> http://allenbrowne.com/casu-08.html
>>
>> The code explains how to build the WhereCondition based on whichever
>> boxes have an entry. You do exactly the same thing for OpenForm as it
>> explains for OpenReport.
>>
>> "Mike Charney" <no*****@everything.net> wrote in message
>> news:fX*****************@newssvr25.news.prodigy.ne t...
>>>I am trying to write an Open Form command in VBA with a where clause
>>>in it.
>>>
>>> I need to be able to do two different where clauses:
>>>
>>> 1) With a between in it: i.e. Between Date1 and Date2 or Between
>>> Data1 and Data2
>>>
>>> 2) With a Like in it: Like *data1* or Like *date1*
>>>
>>> 3) Or a statement with both Between and Like in it.
>>>
>>> I do not know how to make these statements?

Apr 4 '06 #8
Thanks for everyones help.

I have it working.

Mike
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
If the field contains characters, it is not a Number type field.

If you are asking how to pattern match digits in specific places in a Text
field, use the # character.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Mike Charney" <no*****@everything.net> wrote in message
news:Gr****************@newssvr11.news.prodigy.com ...
So how would I do a pattern match on a field that had data like DMH10257
or DMH10096?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
Matching numbers based on the string value of the digits is not
generally useful. For example:
Like "1*"
matches 1, 10, 11, ... 19, 100, 101, ...
which is not really a useful sequence of numbers.

Access will do it, but it is not normally a good design.

"Mike Charney" <no*****@everything.net> wrote in message
news:FZ*******************@newssvr29.news.prodigy. net...
So what happens if I have a text field with numbers in it? Can I use
the str( ) function to change the number to a string, and will it still
search on the filed?

Mike

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44**********************@per-qv1-newsreader-01.iinet.net.au...
> Use the Like operator with Text type fields (not dates or numbers.)
>
> Text fields need quotes as delimiters.
> Use * as the wildcard, or % if the back end is Sql Server.
>
> Example:
> Dim strWhere As String
> If Not IsNull(Me.txtFindCity) Then
> strWhere = "(City Like ""*" & Me.txtFindCity & "*"")"
> End If
>
> If you want an example of how to filter a form based on any
> combination of unbound search controls on different types of fields,
> try:
> http://allenbrowne.com/unlinked/Search2000.zip
> The example requires Access 2000 or later. The code is documented, but
> there is no explanatory article.
>
> "Mike Charney" <no*****@everything.net> wrote in message
> news:ol*****************@newssvr13.news.prodigy.co m...
>> Thanks Allen,
>>
>> That took care of the between condition I needed. Do you know
>> anything about the Like condition in the where clause?
>>
>> Mike
>>
>> "Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
>> news:44**********************@per-qv1-newsreader-01.iinet.net.au...
>>> Check out the example code for Method 2 in this article:
>>> Limiting a Report to a Date Range
>>> at:
>>> http://allenbrowne.com/casu-08.html
>>>
>>> The code explains how to build the WhereCondition based on whichever
>>> boxes have an entry. You do exactly the same thing for OpenForm as
>>> it explains for OpenReport.
>>>
>>> "Mike Charney" <no*****@everything.net> wrote in message
>>> news:fX*****************@newssvr25.news.prodigy.ne t...
>>>>I am trying to write an Open Form command in VBA with a where
>>>>clause in it.
>>>>
>>>> I need to be able to do two different where clauses:
>>>>
>>>> 1) With a between in it: i.e. Between Date1 and Date2 or Between
>>>> Data1 and Data2
>>>>
>>>> 2) With a Like in it: Like *data1* or Like *date1*
>>>>
>>>> 3) Or a statement with both Between and Like in it.
>>>>
>>>> I do not know how to make these statements?


Apr 4 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: John Welch | last post by:
I have a command button with the following code: DoCmd.OpenForm "frmSearchAssignments", , , "SearchAssignmentID = 1" (SearchAssignmentID is the PK, auto number) When it runs, the form opens but...
3
by: Mike Charney | last post by:
I am having trouble with the where clause in an openreport statement in an Access Data Project. I am using MS-Access 2003 with SQL Svr 2000. The line I am using is: DoCmd.OpenReport...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N "APPRAISAL_LESS_PRICE" is not valid in the context where...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
8
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 ,...
5
by: pwiegers | last post by:
Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting 1)nowhere 2) desperate :-) The query is simple: -------- SELECT idUser,...
14
by: keri | last post by:
Hi, Simple version of the question..... How do I use the where clause of the open form command to show an account with a matching ID to be displayed when the form is opened? Eg. I select a...
12
by: =?ISO-8859-1?Q?Ren=E9?= | last post by:
Hi, is there a rule of thumb what is better/faster/more performant in SQL Server 2005? a) SELECT * FROM A INNER JOIN B ON B.ID = A.ID AND B.Cond1 = 1 AND B.Cond2 = 2 b) SELECT * FROM A INNER...
3
by: JenniferM | last post by:
Back again with a brand new problem. My head hurts.... I've got a couple of listboxes on a form, FrmPatientDemographics. One contains knee surgeries for that patient (LbxKneeSx) and the other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.