combo box last info

L

Lonnie

Hey, I have a form with several input options on it, 2 of which are combo
boxes. For speed sake, I would like to have the combo boxes remember the last
input so we can skip over them whenever possible, as we will post several
similar records in a row. Is there an event proceedure i can use to
accomplish this? Also, Im pretty noob, so if you could explain the steps i
need to take I would appricate it.

THanks a million
 
D

Danny J. Lesandrini

One thing you could do, and it has the benefit of being user-specific, is to
save the value to the Registry and read it from there.

In the After Update event of the combo box, you could execute this line ...

SaveSetting "MyApp", "User Defaults", "Combo 001", Me!cboCombo001

Then put this code in the OnCurrent event ...

If Me.NewRecord = True Then
Me!cboCombo001= GetSetting("MyApp", "User Defaults", "Combo 001", NULL)
End If

I love using SaveSetting and GetSetting for this kind of thing. I haven't
noticed any performance issues and it's customized for each user.
 
M

Marshall Barton

Lonnie said:
Hey, I have a form with several input options on it, 2 of which are combo
boxes. For speed sake, I would like to have the combo boxes remember the last
input so we can skip over them whenever possible, as we will post several
similar records in a row. Is there an event proceedure i can use to
accomplish this? Also, Im pretty noob, so if you could explain the steps i
need to take I would appricate it.


You can save the last user entered value in the combo box's
DefaultValue property so it will be automatically applied to
any subsequent new records. Users can override the default
value, then that new value will become the default value.

The code is just one line in the combo box's AfterUpdate
event:

Me.combobox.DefaultValue = """" & Me.combobox & """"
 
L

Lonnie

Marshall, I'm trying this method, but it comes back to the original default
every time, not the last record.
here is my script as it is now:


Option Compare Database
Private Sub Combo14_AfterUpdate()
Me.ComboBox.DefaultValue = """" & Me.ComboBox & """"
End Sub

That should be correct shouldn't it?
 
M

Marshall Barton

Yes, that looks to be correct. Some points to be aware of:

A) The DefaultValue only makes sense on a bound control.

B) The DefaultValue property is applied only when the user
does something (type a character,etc) to start a new
record.

C) Property changes are not saved when the form is closed.
 
L

Lonnie

Danny, I tried this process, but had absolutely no luck-- it was as if I had
done nothing at all--- unless i missed saving the record set to the registry..
 
L

Lonnie

hmmk, I know for certain that the control was unbound when I created it,
because I simply typed the values into the list..... Is there a way to change
that now? I've looked, but cannot find anything.
 
D

Danny J. Lesandrini

Are you saying that the first time you ran this, you got NULL (nothing)?

If so, then it's probably working exactly as it should. Notice below, where the default
result when no registry value is found defaults to NULL. I could have inserted a default
value in here, but I've no idea what it would be.

As soon as you set the combo box value the first time, the registry gets set with the
current combo box value. Though I've modified the code to only update it if the value
is NOT null.


If Nz(Me!cboCombo001, 0) <> 0
SaveSetting "MyApp", "User Defaults", "Combo 001", Me!cboCombo001
End If

Alternatively, you could replace the NULL below with your default value: 0 or 1 or 4397,
whatever the default should be.

If Me.NewRecord = True Then
Me!cboCombo001= GetSetting("MyApp", "User Defaults", "Combo 001", NULL)
End If

Marshall's idea of setting the default value in the control's Default property is probably
much simpler. Again, when you hear hoofbeats, think horses, not zebras.
 
M

Marshall Barton

Lonnie said:
hmmk, I know for certain that the control was unbound when I created it,
because I simply typed the values into the list..... Is there a way to change
that now? I've looked, but cannot find anything.


That's not making much sense to me. If the combo box is
unbound, then it has nothing to do with adding records.

Maybe you're using the word unbound differently. A bound
control has the name of a record source field in its
ControlSource property. It sounds like you are talking
about the RowSource property, which, apparently, you are
using a value list. I think I need more precise information
about the combo box and its role in adding new records.
 
L

Lonnie via AccessMonster.com

marshall and danny---- I figured out I had a corrupt form, and when i remade
it, everything worked as it should.... Thank you both so much for your help,
it is really appriciated.
 

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

Top