Maintaining Selections in Combo Boxex within Forms

rodgo

New Member
Joined
Jun 5, 2003
Messages
40
If I have a form with several combo boxes within it, how can I keep the selections I have made in the combo boxes next time I open the form?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
It depends on what you are doing, the simplest method would be to bind them to a table behind the form but if the form is already bound for data then this wont work.
You will probably need to create some code to update a table on the After Update Event of each box, and have code on the form open event to set them initialy.

Shout if you need more help setting it up

Peter
 
Upvote 0
Dunno -- this may be left field, but you could try writing the combo values to their Tag properties and then reading them back.

Denis
 
Upvote 0
I don't think that writing to Tag properties would be stored between sessions. to do it from the comboBoxes Create a table with just one record in it which has the values you want for the comboboxes.
behind each box add code to the after update Event
Code:
Sub Combo1_AfterUpdate()
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("tblCombos")
With rst
   .Edit
   ' Change data in edit buffer.
   !Field1 = Me.Combo1 
   .Update
   .Close
End With
Set rst = Nothing
End Sub

where tblCombos is the table holding the data for your combos. Field1 is the field containing the data for that combo.

in the Open event of the form you need something like
Code:
Private Sub Form_Open(Cancel As Integer)
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("tblCombos")

With rst
   .MoveFirst
    Me.Combo1 = !Field1
    Me.Combo2 = !Field2
    Me.Combo3 = !Field3


End With
Set rst = Nothing


Hope that makes sense

Peter
 
Upvote 0

Forum statistics

Threads
1,221,808
Messages
6,162,097
Members
451,742
Latest member
JuanMark10

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top