Command box code required.

Andrea

New member
Local time
Today, 18:09
Joined
May 10, 2011
Messages
5
I am sure this will be an easy question for someone to answer. I am creating a database which lists customers contact details.

I have a command box linked to a combo box. When I select something from the drop down list of the combo box (e.g United Kingdom) and click my command box, it then shows me all the clients who live in the United Kingdom.

What I need now is a command which clears the event process I have just asked it to do, meaning that I will see all my records again.

I hope this makes sense and that someone can help me, I am utterly lost!

Thank, Andrea
 
depends how the combo box and the command button work together.

you may just need to clear the combo box.

or you may need to have another command button to undo whatever the previous action did.


maybe post the button click code, and the combo box after update code.

they will be the key events.
 
Thanks for that

the combo box is linked to a query and the command box code looks like this

Private Sub Command381_Click()
Dim query As String
Dim Selectedrole As String


selectedcountry = Combo382.Value


If (selectedcountry = "United Kingdom") Then
query = "select * from [freelance details] where [Country] = 'United Kingdom'"
End If

Does this help at all?

Andrea
 
You should not need to change the record source by using a query. Just use the form's filter to do it:

Code:
Private Sub Command381_Click()
Dim strWhere As String
Dim selectedCountry As String
 
   selectedCountry = [COLOR=red][B]"[Country]=" & Chr(34) &[/B][/COLOR] Combo382.Value [B][COLOR=red]& Chr(34)[/COLOR][/B]
 
   Me.Filter = selectedcountry
   Me.FilterOn = True
End Sub

Then to reset it is just:
Code:
Me.Filter = vbNullString
Me.FilterOn = False
 
Last edited:
Hi Bob

Using the filter would be the easiest option but my boss doesn't want to use the filter box and wants to use combo box instead. I know it sounds silly!

Is there a command for clearing the results from the combo box? Hay, I don't even know if I am making sence!
Kind Regards
Andrea
 
Hi Bob

Using the filter would be the easiest option but my boss doesn't want to use the filter box and wants to use combo box instead.
Did you bother to try my code? It STILL uses the combo box just like you were trying to do. It does NOT use the filter box but it does use the form's filter which is going to work way better for you.
Is there a command for clearing the results from the combo box? Hay, I don't even know if I am making sence!
Kind Regards
Andrea
Well, you can use this to reset the form and the combo box:
Code:
Me.Combo382 = Null
Me.Filter = vbNullString
Me.FilterOn = False
 
Hi Bob

This code does clear the form, however it doesn't then show all my records up again.

Any thoughts?
 
Apologies fro the long delay. I have entered all my information to a table which the form is then linked to.

I have added the criteria of the combo box in a querry.

Does this help?

Andrea
 
why don't you use a cascading combo system instead of VBA?
 
Apologies fro the long delay. I have entered all my information to a table which the form is then linked to.

I have added the criteria of the combo box in a querry.
that is probably the reason. Because the query is dependent upon the combo box you would have to requery the form if the combo is set to null:

Me.Requery
 

Users who are viewing this thread

Back
Top Bottom