Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: criteria expression for list box

Geek News

criteria expression for list box
Gator 11/19/2008 2:57:01 PM
I have a form with two option buttons and a list box. the list box data
depends on what option is selected. Each option used a different table to
draw in the data. However, I have combined the data into one table. The
table contains a list of Accounts.
01 01 01
01 01 02
01 50 01
What I need is when Option1 is selected it draws the accounts that do not
have 50 in the middle and the other Option2 draws only the accounts with 50
in the middle.
Can someone help with the expression?

Here is code I was using in the initial setup using two tables...

Option1 Click
If Option1.value =True then
List1.Rowsource = "SELECT LEFT(ID,2) FROM Table1"
Else
List1.Rowsource = "SELECT LEFT(ID,2) FROM Table2"
End If

Now the RowSource will be the same table just a different criteria. Can
someone help construct?
Re: criteria expression for list box
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> 11/19/2008 3:03:21 PM
No need to have separate tables.

If Option1 =True then
List1.Rowsource = "SELECT ID FROM Table1 " & _
"WHERE Mid(ID, 4, 2) <> "50"
Else
List1.Rowsource = "SELECT ID FROM Table1 " & _
"WHERE Mid(ID, 4, 2) = "50"
End If


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Gator" <Gator[ at ]discussions.microsoft.com> wrote in message
news:92BEF85E-DBFD-4D87-A604-1FE37B6DB35C[ at ]microsoft.com...
[Quoted Text]
>I have a form with two option buttons and a list box. the list box data
> depends on what option is selected. Each option used a different table to
> draw in the data. However, I have combined the data into one table. The
> table contains a list of Accounts.
> 01 01 01
> 01 01 02
> 01 50 01
> What I need is when Option1 is selected it draws the accounts that do not
> have 50 in the middle and the other Option2 draws only the accounts with
> 50
> in the middle.
> Can someone help with the expression?
>
> Here is code I was using in the initial setup using two tables...
>
> Option1 Click
> If Option1.value =True then
> List1.Rowsource = "SELECT LEFT(ID,2) FROM Table1"
> Else
> List1.Rowsource = "SELECT LEFT(ID,2) FROM Table2"
> End If
>
> Now the RowSource will be the same table just a different criteria. Can
> someone help construct?


Re: criteria expression for list box
Gator 11/19/2008 3:42:01 PM
what I'm doing now is querying List2 based on List1 with the following
code...but I'm getting error - expected end of stmt.???

Private Sub List1_Click()

If Option1.Value = True Then

List2.RowSource = "SELECT ID, accountname AS Account FROM Accounts WHERE
MID(ID,4,2) = "50" AND left(ID,2) Like " & "'" & List1 & "*';"

Else

List8.RowSource = "select ID, accountname AS Account from Accounts where
MID(ID,4,2) <> "50" AND left(ID,2) Like " & "'" & List0 & "*';"

End If

End Sub
thanks

"Douglas J. Steele" wrote:

[Quoted Text]
> No need to have separate tables.
>
> If Option1 =True then
> List1.Rowsource = "SELECT ID FROM Table1 " & _
> "WHERE Mid(ID, 4, 2) <> "50"
> Else
> List1.Rowsource = "SELECT ID FROM Table1 " & _
> "WHERE Mid(ID, 4, 2) = "50"
> End If
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Gator" <Gator[ at ]discussions.microsoft.com> wrote in message
> news:92BEF85E-DBFD-4D87-A604-1FE37B6DB35C[ at ]microsoft.com...
> >I have a form with two option buttons and a list box. the list box data
> > depends on what option is selected. Each option used a different table to
> > draw in the data. However, I have combined the data into one table. The
> > table contains a list of Accounts.
> > 01 01 01
> > 01 01 02
> > 01 50 01
> > What I need is when Option1 is selected it draws the accounts that do not
> > have 50 in the middle and the other Option2 draws only the accounts with
> > 50
> > in the middle.
> > Can someone help with the expression?
> >
> > Here is code I was using in the initial setup using two tables...
> >
> > Option1 Click
> > If Option1.value =True then
> > List1.Rowsource = "SELECT LEFT(ID,2) FROM Table1"
> > Else
> > List1.Rowsource = "SELECT LEFT(ID,2) FROM Table2"
> > End If
> >
> > Now the RowSource will be the same table just a different criteria. Can
> > someone help construct?
>
>
>
Re: criteria expression for list box
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> 11/19/2008 10:24:52 PM
It's because you're putting double quotes inside of double quotes (sorry, I
missed that in my original response)

You can use single quotes instead:

Private Sub List1_Click()

If Option1.Value = True Then

List2.RowSource = "SELECT ID, accountname AS Account FROM Accounts WHERE
MID(ID,4,2) = '50' AND left(ID,2) Like '" & List1 & "*';"

Else

List8.RowSource = "select ID, accountname AS Account from Accounts where
MID(ID,4,2) <> '50' AND left(ID,2) Like '" List0 & "*';"

End If


See what Allen Browne has at http://www.allenbrowne.com/casu-17.html for
more on quotes in quotes.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Gator" <Gator[ at ]discussions.microsoft.com> wrote in message
news:D960C262-AAF8-44DB-B332-F2DC9843FBB6[ at ]microsoft.com...
[Quoted Text]
> what I'm doing now is querying List2 based on List1 with the following
> code...but I'm getting error - expected end of stmt.???
>
> Private Sub List1_Click()
>
> If Option1.Value = True Then
>
> List2.RowSource = "SELECT ID, accountname AS Account FROM Accounts WHERE
> MID(ID,4,2) = "50" AND left(ID,2) Like " & "'" & List1 & "*';"
>
> Else
>
> List8.RowSource = "select ID, accountname AS Account from Accounts where
> MID(ID,4,2) <> "50" AND left(ID,2) Like " & "'" & List0 & "*';"
>
> End If
>
> End Sub
> thanks
>
> "Douglas J. Steele" wrote:
>
>> No need to have separate tables.
>>
>> If Option1 =True then
>> List1.Rowsource = "SELECT ID FROM Table1 " & _
>> "WHERE Mid(ID, 4, 2) <> "50"
>> Else
>> List1.Rowsource = "SELECT ID FROM Table1 " & _
>> "WHERE Mid(ID, 4, 2) = "50"
>> End If
>>
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Gator" <Gator[ at ]discussions.microsoft.com> wrote in message
>> news:92BEF85E-DBFD-4D87-A604-1FE37B6DB35C[ at ]microsoft.com...
>> >I have a form with two option buttons and a list box. the list box data
>> > depends on what option is selected. Each option used a different table
>> > to
>> > draw in the data. However, I have combined the data into one table.
>> > The
>> > table contains a list of Accounts.
>> > 01 01 01
>> > 01 01 02
>> > 01 50 01
>> > What I need is when Option1 is selected it draws the accounts that do
>> > not
>> > have 50 in the middle and the other Option2 draws only the accounts
>> > with
>> > 50
>> > in the middle.
>> > Can someone help with the expression?
>> >
>> > Here is code I was using in the initial setup using two tables...
>> >
>> > Option1 Click
>> > If Option1.value =True then
>> > List1.Rowsource = "SELECT LEFT(ID,2) FROM Table1"
>> > Else
>> > List1.Rowsource = "SELECT LEFT(ID,2) FROM Table2"
>> > End If
>> >
>> > Now the RowSource will be the same table just a different criteria.
>> > Can
>> > someone help construct?
>>
>>
>>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net