Command Button Queries

D

DS

I have an unbound field that I want to change the content of depending
on which button you click. I have 5 different buttons. I attached a
query to each but I don't understand how to change the content in the
unbound field. Any suggestions?
Thanks
DS
 
R

Rick B

You don't tell us what you want to change the field to.

What are your five buttons?

When you click the first one, you want a particular value to appear in your
tect box?

If so, you'd simply put "click" event code tied to your button with
something like...

Me.SomeTextField = "SelectionA"


Give us more details if that does not answer your question,
Rick B
 
R

Rick B

Also, how did you "attach a query to a button"? Have no idea what that
sentence means.
 
D

DS

Rick said:
Also, how did you "attach a query to a button"? Have no idea what that
sentence means.
Ok, I hope I can clarify this. I have a list box. I also have 5
Command Buttons named as such... "New Check", "Reopen Check", "Print
Check", "Pay Check" and "Transfer Check". I have a query that I made
for each one of these to get the appropiate info, which in this case are
Table Numbers. What I need to do is when I click on one of the command
buttons it will fill the list box with the appropiate table numbers. I
hope this is clearer. Thank you for any help or suggestions.
DS
 
M

Mauricio Silva

I would do this :

1- Create a function called UpdateCheckList

Private Function UpdateCheckList(aQuery As Integer)
Dim strSQL As String

Select Case aQuery
Case 1: strSQL = Query1 ' Change this for "New Check" query
Case 2: strSQL = Query2 ' Same to Reopen Check
Case 3: strSQL = Query3 ' ...
Case 4: strSQL = Query4 '...
Case 5: strSQL = Query5 '...
End Select

List0.RowSource = strSQL
End Function

Change List0 to the name of your list box
Change Query1 to Query5 to your queries

2- Put in the event OnClick of NewCheck button:
=UpdateCheckList(1)

3- OnClick of Reopen Check button
= UpdateCheckList(2)

and goes on to the 5th button


I hope I helped

Mauricio Silva
 
V

Van T. Dinh

Check Access Help / Access VB Help on the RowSource Property of the ListBox.

You can use the Comand_Button to assign the Query to the RowSource of the
ListBox.
 
D

DS

Mauricio said:
I would do this :

1- Create a function called UpdateCheckList

Private Function UpdateCheckList(aQuery As Integer)
Dim strSQL As String

Select Case aQuery
Case 1: strSQL = Query1 ' Change this for "New Check" query
Case 2: strSQL = Query2 ' Same to Reopen Check
Case 3: strSQL = Query3 ' ...
Case 4: strSQL = Query4 '...
Case 5: strSQL = Query5 '...
End Select

List0.RowSource = strSQL
End Function

Change List0 to the name of your list box
Change Query1 to Query5 to your queries

2- Put in the event OnClick of NewCheck button:
=UpdateCheckList(1)

3- OnClick of Reopen Check button
= UpdateCheckList(2)

and goes on to the 5th button


I hope I helped

Mauricio Silva
:
Great Thanks, I'll give it a whirl.
DS
 
D

DS

Mauricio said:
I would do this :

1- Create a function called UpdateCheckList

Private Function UpdateCheckList(aQuery As Integer)
Dim strSQL As String

Select Case aQuery
Case 1: strSQL = Query1 ' Change this for "New Check" query
Case 2: strSQL = Query2 ' Same to Reopen Check
Case 3: strSQL = Query3 ' ...
Case 4: strSQL = Query4 '...
Case 5: strSQL = Query5 '...
End Select

List0.RowSource = strSQL
End Function

Change List0 to the name of your list box
Change Query1 to Query5 to your queries

2- Put in the event OnClick of NewCheck button:
=UpdateCheckList(1)

3- OnClick of Reopen Check button
= UpdateCheckList(2)

and goes on to the 5th button


I hope I helped

Mauricio Silva
:
Maurice I tried this and whenever I click on the button it says that it
can't find the function...am I doing something wrong?

Private Function UpdateCheckList(aQuery As Integer)
Dim strSQL As String
Select Case aQuery
Case 1: strSQL = NewCheckQ
Case 2: strSQL = Query2
Case 3: strSQL = Query3
Case 4: strSQL = Query4
Case 5: strSQL = Query5
End Select
TableNum.RowSource = strSQL
End Function

And on the on Click property of the button I have....

=UpdateCheckList(1)

Thanks
DS
 
M

Mauricio Silva

Actually yes:

you are suposed to change:
Case 1: strSQL = NewCheckQ

to your actual query:
Case 1: strSQL = "SELECT * FROM [...]"

or the name of your query (in quotes, as string)
Case 1: strSQL = "NewCheckQ"

and do the same for case2 to 5.

If you thing this is going to be a mess, you could use constants:

const strQuery1 = "SELECT * FROM [yourtable]..."
(...)
Case 1: strSQL = strQuery1


Mauricio Silva
 
D

DS

Mauricio said:
Actually yes:

you are suposed to change:
Case 1: strSQL = NewCheckQ

to your actual query:
Case 1: strSQL = "SELECT * FROM [...]"

or the name of your query (in quotes, as string)
Case 1: strSQL = "NewCheckQ"

and do the same for case2 to 5.

If you thing this is going to be a mess, you could use constants:

const strQuery1 = "SELECT * FROM [yourtable]..."
(...)
Case 1: strSQL = strQuery1


Mauricio Silva

Maurice I tried this and whenever I click on the button it says that it
can't find the function...am I doing something wrong?

Private Function UpdateCheckList(aQuery As Integer)
Dim strSQL As String
Select Case aQuery
Case 1: strSQL = NewCheckQ
Case 2: strSQL = Query2
Case 3: strSQL = Query3
Case 4: strSQL = Query4
Case 5: strSQL = Query5
End Select
TableNum.RowSource = strSQL
End Function

And on the on Click property of the button I have....

=UpdateCheckList(1)

Thanks
DS
Thanks, I'll give it a try.
DS
 
Top