Combo Box Default = Last

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a combo box on a form that is a production entry form in data entry
mode. A machine operator will be picking a project name and then entering
time and part information for each part. For a whole shift the operator
might work on 15 different parts all from the same project. The project name
is in a Combo Box, Combo0 and is saved in projnamek2. The projnamek2 field
drives a series of sub forms on the main form.

Any help you can provide so that the initial selection in Combo0 can be the
default once the machine operator tabs out would be greatly appreciated.
 
Consider putting a bit of code in the combo box's AfterUpdate event. You
could use something like (untested, your syntax may vary):

Me.cboYourComboBoxName.DefaultValue = Me.cboYourComboBoxName

That may take a little tweaking, but I suspect it will put the value (i.e.,
the bound column value, probably an ID) of the combobox in the combo box's
default value.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Try setting the DefaultValue property of the combobox in its AfterUpdate
procedure (which runs when a selection has been made).

Private Sub Combo0_AfterUpdate()
Combo0.DefaultValue = Combo0.Value
End Sub

If the bound column of the combo is text, not numeric, then you will need to
surround the value in quotes:

Combo0.DefaultValue = """" & Combo0.Value & """"
 
There are a few different ways to do this.

If you're comfortable with VBA code, you could set a module-level
variable in the form_before update event and then consume it in the
form's OnCurrent event.

You could also use a function like DLookup or DMax against the form's
table source. For example, you might have a primary key field on the
table that is an autonumber, so you'd use
DLookup("projnakek2","MyTableName","[MyIdField] = " &
DMax("MyIdField","MyTableName")).
This would return the last project name from the table. You'd put this
statement in the combobox's Default Value property.

HTH,
Barry
 
tjdaly,
Try making the latest selection from Combo0 the DefaultValue for Combo0. Use the
AfterUpdate event of Combo0...
Combo0.DefaultValue = " ' " & Combo0 & " ' "
(I expanded the correct "'" to " ' " so you could see the quotes... remove the
spaces on your code)

If you set Combo0 to value "SomeProjectName" it will automatically enter that default
into any new record... until you change it to another ProjectName... then that will be the
default for any new record... until you change it... etc.. etc..
 

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