Recalling previous data to a combo box.

mr_sd

Registered User.
Local time
Today, 22:55
Joined
May 11, 2004
Messages
24
I have a DB which requires staff to select their name from a list when taking a booking.

Is there an easy way of the combo box remembering what was selected last when the form is opened, rather than the staff member have to select it every time they take a booking.

I.E. Bob takes a booking and selects "Bob" in the "booked-by" field. The form is closed and the next time it is opened "Bob" is in the "booked-by" field until someone else selects their name.

The combo box gets its data from one column in table "tbl_staff".

Cheers, Rich.
 
On the AfterUpdate event you could put the selected value into the combo's Tag property and, on the Current Event, test if a new record is opened and, if so, put the contents of the combo's Tag into the combo.

A smarter approach would be to have a table for your users like this:

UserID
Forename
Surname
SysCode

Where SysCode is the user's actual computer logon name. A quick DLookup (oxymoron? :D) will get the user ID and fill it in form you.
 
Ok, i've tried the vb code in the after update of "booked-by":

Me.Booked-by.Tag = Me.Booked-by

I close the form, open it in design view and the tag is null. :(

I havent quite got to playing with dlookup yet as I'm scared of messing up our customer database!! (as it's not me who originally designed it!)
 
Sorry, I didn't realise you'd be closing the form and then reopening it.

In a module (a standalone one) you can declare a global variable that you can assign the combo's value to:

Public lngUserID As Long ' use long as combo - ideally - will have UserID, username (concatenation of fore- and sur-names)

You can then store the UserID to this variable.




Also, DLookup won't harm your data. It only looks at it. Like opening a book but not scribbling on it with a big crayon. :)
 
Sorry - my vb knowledge is pretty basic

Any chance of some example code and (how) would I call the module from the afterupdate of "booked-by"?

Cheers, Rich.
 
You don't call a module. A module is just a container for code.

Anyway, here's a quick example
 

Attachments

Mile-O-Phile said:
You don't call a module. A module is just a container for code.

Anyway, here's a quick example

Cheers! :D

U'r a star!
 

Users who are viewing this thread

Back
Top Bottom