Reset a combobox rowsource to it's default value (1 Viewer)

Saphirah

Active member
Local time
Today, 11:31
Joined
Apr 5, 2020
Messages
163
Hello everyone,

i have a combobox in an access form. The rowsource is set to a table in my database.
Now whenever the user does a specific action i change the row source using VBA to display different values.
Whenever i close the form and reopen it again, the rowsource is set back to it's default value.

Now is there a possibility to "reset" the row source to it's default value using VBA without closing the form?

I know i can simply store the rowsource in a variable when opening the form, so this is more of a "good to know".
But there might be an easier solution!

Thanks for your help everyone ;)
 

jdraw

Super Moderator
Staff member
Local time
Today, 05:31
Joined
Jan 23, 2006
Messages
15,379
Now whenever the user does a specific action i change the row source using VBA to display different values.
I recommend that you make one of the different values the "default". And based on your logic set the rowsource to that value as appropriate.
 

Saphirah

Active member
Local time
Today, 11:31
Joined
Apr 5, 2020
Messages
163
I recommend that you make one of the different values the "default". And based on your logic set the rowsource to that value as appropriate.
I think you misunderstood my intentions. What i wanted to do is reset the row source to it's default value.
So i change the Row Source SQL String, to show different data using VBA. How do i revert back to it's default value/state?
How do i revert back to the row source that is set when i opened the form?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:31
Joined
May 7, 2009
Messages
19,232
when the Form Load event, save the rowsource of the combo to variable:
you can add a command button to reinstate the combo:

option compare database
option explicit

Dim combo_rowsource as string

private form_load()
combo_rowsource = me!combo.rowsource
end sub

'say your command button is named button1:

private sub button1_click()
me!combo.rowsource = combo_rowsource
end sub
 

Saphirah

Active member
Local time
Today, 11:31
Joined
Apr 5, 2020
Messages
163
when the Form Load event, save the rowsource of the combo to variable:
you can add a command button to reinstate the combo:

option compare database
option explicit

Dim combo_rowsource as string

private form_load()
combo_rowsource = me!combo.rowsource
end sub

'say your command button is named button1:

private sub button1_click()
me!combo.rowsource = combo_rowsource
end sub
Alright, guess i will go with that :)
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:31
Joined
Feb 19, 2002
Messages
43,223
Not sure why you are changing the rowsource of the combo. You don't need to do that if the dependent combo uses criteria that references the parent combo.

But, if you just have two options, make two queries and save them. Then change the RowSource to the querydef you want.
 

Users who are viewing this thread

Top Bottom