assigning default value to combo box

  • Thread starter Thread starter Todd
  • Start date Start date
T

Todd

I have a form which contains a combo box that allows my
users to enter which Shift they are on, which is saved
with each status record that they enter.

I have a table that looks like this.

Shift User
A Bill
B Ted
C Mark
A Betty
A Jen
C Fred

Right now the way the combo box is setup, the rowsource
contains a query which returns the different shift letters
as choices in the combo box.

What I want to do is make it so that the default value for
the combo box is the users normal shift (ie per the
table). Each users database username is the same as the
value in this table so I'm hoping I can use the CurrentUser
()function, compare it to the values in this table, and
return the default value as the correct shift per the
table. I want to keep the combo box format, because
occasionally people work different shifts, so I still want
them to have the option to change the shift entry.

Can anyone help with this? Although I know how to write
the query to do this, I can't seem to make a query work
for the default value.

The query that works is:

SELECT [ShiftList].[Shift] FROM [ShiftList] WHERE
(((CurrentUser())=[ShiftList].[User]));
 
Hi Todd

try to add this lines of code in the Form_Open Event

Dim sShift As Strin
Const DQ = """

'get the Shift ID for the current use

sShift = Nz(DLookup("Shift", "ShiftList", "User='" & CurrentUser & "'"), ""
'check to see if you got valid shift i
If Len(sShift) > 0 The
Me.Combo1.DefaultValue = DQ & sShift & D
End I


----- Todd wrote: ----

I have a form which contains a combo box that allows my
users to enter which Shift they are on, which is saved
with each status record that they enter

I have a table that looks like this

Shift Use
A Bil
B Te
C Mar
A Bett
A Je
C Fre

Right now the way the combo box is setup, the rowsource
contains a query which returns the different shift letters
as choices in the combo box

What I want to do is make it so that the default value for
the combo box is the users normal shift (ie per the
table). Each users database username is the same as the
value in this table so I'm hoping I can use the CurrentUse
()function, compare it to the values in this table, and
return the default value as the correct shift per the
table. I want to keep the combo box format, because
occasionally people work different shifts, so I still want
them to have the option to change the shift entry

Can anyone help with this? Although I know how to write
the query to do this, I can't seem to make a query work
for the default value

The query that works is

SELECT [ShiftList].[Shift] FROM [ShiftList] WHERE
(((CurrentUser())=[ShiftList].[User]));
 
Back
Top