Command Button Queries

  • Thread starter Thread starter DS
  • Start date Start date
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
 
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
 
Also, how did you "attach a query to a button"? Have no idea what that
sentence means.
 
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
 
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
 
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.
 
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
 
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
 
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
 
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
 

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

Back
Top