change default value for combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've a form with multiple combo boxes where the user selects an option, and
each of these combo boxes has a "related" control in which the user enters a
price for the option selected.

What I'm trying to do is to set a default value in both the combo box and
price control if the user selects a value in a SwareID control previously (on
the same form).

I've written an after update event procedure:

Private Sub SwareID_AfterUpdate()
If Me!SwareID = "WILES21L9" Then
Me!QWilcomOpt1 = "Smart Font Wilcom ES21"
Me!QWilcomOptPrice1 = 1000
Else
If Me!SwareID = "WILES21E9" Then
Me!QWilcomOpt1 = "Smart Font Wilcom ES21"
Me!QWilcomOptPrice1 = 1000
Else
If Me!SwareID = "WILES21D9" Then
Me!QWilcomOpt1 = "Smart Font Wilcom ES21"
Me!QWilcomOptPrice1 = 1000
Me!QWilcomOpt2 = "Auto Appliqué Wilcom ES21D (requires Input C)"
Me!QWilcomOptPrice2 = 1300
End If
End If
End If

End Sub

The controls for the QWilcomOptPrice1, 2 etc. fields display the values
correctly according to the code above, however, the QWilcomOpt1, 2 etc.
controls are still blank. These are the combo box controls, so I figure
there is something else I need to do.

Can anyone offer any suggestions?

Thanks, Sue.
 
Sue said:
Hi,

I've a form with multiple combo boxes where the user selects an option, and
each of these combo boxes has a "related" control in which the user enters a
price for the option selected.

What I'm trying to do is to set a default value in both the combo box and
price control if the user selects a value in a SwareID control previously (on
the same form).

I've written an after update event procedure:

Private Sub SwareID_AfterUpdate()
If Me!SwareID = "WILES21L9" Then
Me!QWilcomOpt1 = "Smart Font Wilcom ES21"
Me!QWilcomOptPrice1 = 1000
Else
If Me!SwareID = "WILES21E9" Then
Me!QWilcomOpt1 = "Smart Font Wilcom ES21"
Me!QWilcomOptPrice1 = 1000
Else
If Me!SwareID = "WILES21D9" Then
Me!QWilcomOpt1 = "Smart Font Wilcom ES21"
Me!QWilcomOptPrice1 = 1000
Me!QWilcomOpt2 = "Auto Appliqué Wilcom ES21D (requires Input C)"
Me!QWilcomOptPrice2 = 1300
End If
End If
End If

End Sub

The controls for the QWilcomOptPrice1, 2 etc. fields display the values
correctly according to the code above, however, the QWilcomOpt1, 2 etc.
controls are still blank. These are the combo box controls, so I figure
there is something else I need to do.

Can anyone offer any suggestions?

Thanks, Sue.

Sue,

The code looks right and, with my limited testing, appears to run correctly.

For a combo box control, under Properites/Format, what is the 'Column
Count'? And what are the 'Row source' field types?

Usually, the 'Row Source Type' is a Table/Query with 2 or more field, with
the first field as the 'Bound Column' (type numeric/Long) and Text, Date,
etc. for the rest of the fields.

In your case, I would guess the 'Bound Column' field type is numeric (Long
Integer/Autonumber) and the second field is a text field that holds the
description.

If so, your code is trying to put a string into a numeric field. Use the PK
field value instead of the text, i.e. if "Smart Font Wilcom ES21" has a PK
of 5 in the table, then change the code to:

Me!QWilcomOpt1 = 5 ' for "Smart Font Wilcom ES21"

or

Me!QWilcomOpt2 = 10 ' for "Auto Appliqué Wilcom ES21D (requires Input C)"


HTH
Steve
 
Back
Top