Changing DefaultValue of a ComboBox at Runtime

D

David C. Holley

I'm trying to change the default value of a comboBox via code. The
problem that I'm having is that the default value is not being displayed
in the combobox [cboBillingMethod] nor is it being stored in the record.
I have confirmed that the code is functioning properly in that the
default values for [cboClient] and [cboMasterAccount] are being set AND
are being used when a new record is added. When I checked the default
value of [cboBillingMethod] via the immediate window, it is being set -
its just not being used.

So what am I missing?

David H

DoCmd.OpenForm "frmReservations", acNormal, , , acFormAdd
Select Case [Forms]![frmInvoicing]![txtAccountType]
Case "client"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "client"
[Forms]![frmReservations]![cboBillingMethod].Value = "client"
[Forms]![frmReservations]![cboClient].DefaultValue =
[Forms]![frmInvoicing]![lngClientID]
[Forms]![frmReservations]![cboClient].Value =
[Forms]![frmInvoicing]![lngClientID]
Case "master account"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "master"
[Forms]![frmReservations]![cboBillingMethod].Value = "master"
[Forms]![frmReservations]![cboMasterAccount].DefaultValue =
[Forms]![frmInvoicing]![lngMasterAccountID]
[Forms]![frmReservations]![cboMasterAccount].Value =
[Forms]![frmInvoicing]![lngMasterAccountID]
End Select
 
J

John Nurick

Have you experimented with the form's Repaint and Refresh methods, or
perhaps with requerying the comboboxes?

I'm trying to change the default value of a comboBox via code. The
problem that I'm having is that the default value is not being displayed
in the combobox [cboBillingMethod] nor is it being stored in the record.
I have confirmed that the code is functioning properly in that the
default values for [cboClient] and [cboMasterAccount] are being set AND
are being used when a new record is added. When I checked the default
value of [cboBillingMethod] via the immediate window, it is being set -
its just not being used.

So what am I missing?

David H

DoCmd.OpenForm "frmReservations", acNormal, , , acFormAdd
Select Case [Forms]![frmInvoicing]![txtAccountType]
Case "client"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "client"
[Forms]![frmReservations]![cboBillingMethod].Value = "client"
[Forms]![frmReservations]![cboClient].DefaultValue =
[Forms]![frmInvoicing]![lngClientID]
[Forms]![frmReservations]![cboClient].Value =
[Forms]![frmInvoicing]![lngClientID]
Case "master account"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "master"
[Forms]![frmReservations]![cboBillingMethod].Value = "master"
[Forms]![frmReservations]![cboMasterAccount].DefaultValue =
[Forms]![frmInvoicing]![lngMasterAccountID]
[Forms]![frmReservations]![cboMasterAccount].Value =
[Forms]![frmInvoicing]![lngMasterAccountID]
End Select
 
D

David C. Holley

I would however, its working for [cboClient] and [cboMasterAccount]. My
conclusion is there's something about [cboBillingMethod] itself as
opposed to the code. All three boxes are essentially the same -
comboBoxes loaded from a Select Query with multiple columns, the first
column being the bound column, with the others hidden via ColumnWidths
set to 0. I'm going to try deleing the comboBox and copying one of the
boxes that is working.

John said:
Have you experimented with the form's Repaint and Refresh methods, or
perhaps with requerying the comboboxes?

I'm trying to change the default value of a comboBox via code. The
problem that I'm having is that the default value is not being displayed
in the combobox [cboBillingMethod] nor is it being stored in the record.
I have confirmed that the code is functioning properly in that the
default values for [cboClient] and [cboMasterAccount] are being set AND
are being used when a new record is added. When I checked the default
value of [cboBillingMethod] via the immediate window, it is being set -
its just not being used.

So what am I missing?

David H

DoCmd.OpenForm "frmReservations", acNormal, , , acFormAdd
Select Case [Forms]![frmInvoicing]![txtAccountType]
Case "client"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "client"
[Forms]![frmReservations]![cboBillingMethod].Value = "client"
[Forms]![frmReservations]![cboClient].DefaultValue =
[Forms]![frmInvoicing]![lngClientID]
[Forms]![frmReservations]![cboClient].Value =
[Forms]![frmInvoicing]![lngClientID]
Case "master account"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "master"
[Forms]![frmReservations]![cboBillingMethod].Value = "master"
[Forms]![frmReservations]![cboMasterAccount].DefaultValue =
[Forms]![frmInvoicing]![lngMasterAccountID]
[Forms]![frmReservations]![cboMasterAccount].Value =
[Forms]![frmInvoicing]![lngMasterAccountID]
End Select
 
D

David C. Holley

I would however, its working for [cboClient] and [cboMasterAccount]. My
conclusion is there's something about [cboBillingMethod] itself as
opposed to the code. All three boxes are essentially the same -
comboBoxes loaded from a Select Query with multiple columns, the first
column being the bound column, with the others hidden via ColumnWidths
set to 0. I tried completely deleting the comboBox and placed a new text
box created from directly from the TOOLBOX and in that instance when I
went to a new record, the default value displayed was the ever popular
#NAME? error. Again when I checked the immediate window, the
..defaultValue was as expected. I even tried completely changing the name
of the control (and the appropriate code) and still got the #NAME? error
on a new record. I even tried setting the default value to 'CA' or 'MA'
to ensure that I wasn't using some sort of reserved word. No luck.

David H

John said:
Have you experimented with the form's Repaint and Refresh methods, or
perhaps with requerying the comboboxes?

I'm trying to change the default value of a comboBox via code. The
problem that I'm having is that the default value is not being displayed
in the combobox [cboBillingMethod] nor is it being stored in the record.
I have confirmed that the code is functioning properly in that the
default values for [cboClient] and [cboMasterAccount] are being set AND
are being used when a new record is added. When I checked the default
value of [cboBillingMethod] via the immediate window, it is being set -
its just not being used.

So what am I missing?

David H

DoCmd.OpenForm "frmReservations", acNormal, , , acFormAdd
Select Case [Forms]![frmInvoicing]![txtAccountType]
Case "client"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "client"
[Forms]![frmReservations]![cboBillingMethod].Value = "client"
[Forms]![frmReservations]![cboClient].DefaultValue =
[Forms]![frmInvoicing]![lngClientID]
[Forms]![frmReservations]![cboClient].Value =
[Forms]![frmInvoicing]![lngClientID]
Case "master account"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "master"
[Forms]![frmReservations]![cboBillingMethod].Value = "master"
[Forms]![frmReservations]![cboMasterAccount].DefaultValue =
[Forms]![frmInvoicing]![lngMasterAccountID]
[Forms]![frmReservations]![cboMasterAccount].Value =
[Forms]![frmInvoicing]![lngMasterAccountID]
End Select
 
D

David C. Holley

Tried a few other things and then made this observation...

One observation [cboClient] and [cboMasterAccount] and the underlying
table fields store numeric values whereas [cboBillingMethod] and its
field store a text field. I suspect that there's something going on here.

David H

John said:
Have you experimented with the form's Repaint and Refresh methods, or
perhaps with requerying the comboboxes?

I'm trying to change the default value of a comboBox via code. The
problem that I'm having is that the default value is not being displayed
in the combobox [cboBillingMethod] nor is it being stored in the record.
I have confirmed that the code is functioning properly in that the
default values for [cboClient] and [cboMasterAccount] are being set AND
are being used when a new record is added. When I checked the default
value of [cboBillingMethod] via the immediate window, it is being set -
its just not being used.

So what am I missing?

David H

DoCmd.OpenForm "frmReservations", acNormal, , , acFormAdd
Select Case [Forms]![frmInvoicing]![txtAccountType]
Case "client"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "client"
[Forms]![frmReservations]![cboBillingMethod].Value = "client"
[Forms]![frmReservations]![cboClient].DefaultValue =
[Forms]![frmInvoicing]![lngClientID]
[Forms]![frmReservations]![cboClient].Value =
[Forms]![frmInvoicing]![lngClientID]
Case "master account"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "master"
[Forms]![frmReservations]![cboBillingMethod].Value = "master"
[Forms]![frmReservations]![cboMasterAccount].DefaultValue =
[Forms]![frmInvoicing]![lngMasterAccountID]
[Forms]![frmReservations]![cboMasterAccount].Value =
[Forms]![frmInvoicing]![lngMasterAccountID]
End Select
 
D

David C. Holley

Fixed the problem - needed to add quotes into the string that the
defaultValue was being set to... chr(34) & "client" & chr(34) did
the trick. (And to think that I was breathing tire cleaner when it came
to me...)

David H
Tried a few other things and then made this observation...

One observation [cboClient] and [cboMasterAccount] and the underlying
table fields store numeric values whereas [cboBillingMethod] and its
field store a text field. I suspect that there's something going on here.

David H

John said:
Have you experimented with the form's Repaint and Refresh methods, or
perhaps with requerying the comboboxes?

I'm trying to change the default value of a comboBox via code. The
problem that I'm having is that the default value is not being
displayed in the combobox [cboBillingMethod] nor is it being stored
in the record. I have confirmed that the code is functioning properly
in that the
default values for [cboClient] and [cboMasterAccount] are being set AND
are being used when a new record is added. When I checked the default
value of [cboBillingMethod] via the immediate window, it is being set
- its just not being used.

So what am I missing?

David H

DoCmd.OpenForm "frmReservations", acNormal, , , acFormAdd
Select Case [Forms]![frmInvoicing]![txtAccountType]
Case "client"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "client"
[Forms]![frmReservations]![cboBillingMethod].Value = "client"
[Forms]![frmReservations]![cboClient].DefaultValue =
[Forms]![frmInvoicing]![lngClientID]
[Forms]![frmReservations]![cboClient].Value =
[Forms]![frmInvoicing]![lngClientID]
Case "master account"
[Forms]![frmReservations]![cboBillingMethod].DefaultValue = "master"
[Forms]![frmReservations]![cboBillingMethod].Value = "master"
[Forms]![frmReservations]![cboMasterAccount].DefaultValue =
[Forms]![frmInvoicing]![lngMasterAccountID]
[Forms]![frmReservations]![cboMasterAccount].Value =
[Forms]![frmInvoicing]![lngMasterAccountID]
End Select
 
J

John Nurick

Fixed the problem - needed to add quotes into the string that the
defaultValue was being set to... chr(34) & "client" & chr(34) did
the trick. (And to think that I was breathing tire cleaner when it came
to me...)

One mind-altering substance is as good as another?
 

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