default to first item in combo box list

S

SuzyQ

How can I get access to use the first item in the list of a combo box on a
form if the field in question is currently null? I'm trying to speed up data
entry, and 99.9% of the time on this particular combo box, the first item in
the list is the item the user chooses. It would be nice if they could just
tab throug the field and it would populate rather than having to select from
the list. Then on the rare case where they select something other than the
first item on the list, they could select it.
 
F

fredg

How can I get access to use the first item in the list of a combo box on a
form if the field in question is currently null? I'm trying to speed up data
entry, and 99.9% of the time on this particular combo box, the first item in
the list is the item the user chooses. It would be nice if they could just
tab throug the field and it would populate rather than having to select from
the list. Then on the rare case where they select something other than the
first item on the list, they could select it.

What is the Combo Row Source?
What is the first item in the list?
Is that first item always the same item?

Set the default value to whatever the value is of the bound column
first row.
For example, if the Rowsource returns CompanyID and CompanyName
fields, and the CompanyID of the Company you mostly use is 456, then
set the Combo default value property to 456.
Note: the default value can be anywhere in the list, not just the
first item.

The Default value only comes into usage on new records.
If you have something else as row source, then you need to give us
more information.
 
M

Mr. B

SuzyQ,

If you want to assign the first value in your combo box to be the value of
the combo box for each new record add the following code to the OnCurrent
event of your form:

If Me.NewRecord Then
Me.NameOfComboBox= Me.NameOfComboBox.ItemData(0)
End If

Just change the "NameOfComboBox" to the actual name of your combo box.
 
S

SuzyQ

What is the Combo Row Source? it is a query = "SELECT
[tblJobLine].[LineNo], [tblLineNumbers].[Description], [tblJobLine].[JobCode]
FROM tblJobLine INNER JOIN tblLineNumbers ON
[tblJobLine].[LineNo]=[tblLineNumbers].[LineNo] WHERE
((([tblJobLine].[JobCode])=[forms].[frmTimeSheet].[txtJobCode] Or
([tblJobLine].[JobCode])=[forms].[frmTimeSheet].[txtAdminCode])) ORDER BY
[tblJobLine].[LineNo]; "
What is the first item in the list? varies depending on the data in the JobCode field
Is that first item always the same item? no

The default for the particular jobcode is always at the top of the query
data for the current record, however it is not the same for all job codes.
For instance if jobcode = "025" then lineno can be "25", "26", or "47" - "25"
is listed first
jobcode = "073" then lineno can be "44", or "47" - "44" is listed first
jobcode = "165" then lineno can be "37" or "47" - "37" is listed first

however until jobcode is entered the query just has a "47" record. Once the
job code is entered the lineno field requeries and the list is updated. As
you tab through the fields (lineno tab order is sometime after jobcodes tab
number so it is after lineno) rather than droping the list down to select (or
even as soon as JobCode has been updated) I want lineno to take the value of
the first item of the query for that field.
 
S

SuzyQ

I did it this way (see response to fredg for reason), but the code you gave
was what I was looking for. Thanks

Private Sub JobCode_AfterUpdate()
[Forms]![frmTimeSheet]!txtJobCode = Me.JobCode
Me.LineNo.Requery
Me.LineNo = Me.LineNo.ItemData(0)
End Sub
 

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

Similar Threads


Top