Combo Box Data Doesn't Display

K

Kevin Sprinkel

On a continuous subform, cboSteelSizes gets its rows from
a query formed in the AfterUpdate event of the previous
control, cboSteelType. Since the user frequently enters
data for a single type all at once, I set the default
value for cboSteelType in the same event, and disable it.
A command button on the main form enables the control when
the user is ready to enter values for a different type.

Since one type is much more common than the others, I've
set the default value for cboSteelType and
cboSteelSizes.RowSource in form design view
correspondingly.

I've been testing the form today, and it seemed ready to
publish EXCEPT...

If I leave the form and come back to it, those rows in
which cboSteelType equals some value other than the
default does not display its value in cboSteelSize. If I
change the default steel type, and then click in the
field, the value *magically* reappears, and nothing
happens to those associated with the prior default type;
they continue to display.

Does anyone know why this is happening and how to correct
it?

Private Sub Form_Activate()
' Main form OnActivate procedure

On Error GoTo ErrHandler
DoCmd.Maximize
Me!sbfSteelTakeoff.SetFocus
Me!sbfSteelTakeoff!cboSteelSize.SetFocus
DoCmd.GoToRecord , , acNewRec

ErrExit:
Exit Sub

ErrHandler:
MsgBox Err.Description
Resume ErrExit

End Sub

Private Sub cboSteelType_AfterUpdate()
'1st Combo Box

Dim strDefaultRowSource As String
Dim strWhereClause As String
Dim strOrderByClause As String

' Set Default Value to the newly entered value and clear
any entered size
Me!cboSteelType.DefaultValue = Me!cboSteelType
Me!cboSteelSize = Null

' Set Row Source of cboSteelSize to those matching the
steel type

strDefaultRowSource = "SELECT tblSteelSizes.SteelSizeID,
tblSteelSizes.SteelSize, " & _
"tblSteelSizes.LBPerLF, tblSteelSizes.SFPerLF FROM
tblSteelSizes "
strWhereClause = "WHERE (((tblSteelSizes.SteelType) = "
& Me!cboSteelType & ")) "
strOrderByClause = "ORDER BY tblSteelSizes.SteelSize;"

Me!cboSteelSize.RowSource = strDefaultRowSource &
strWhereClause & strOrderByClause

' Move focus to Steel Size and disable SteelType control
Me!cboSteelSize.SetFocus
Me!cboSteelType.Enabled = False
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

Top