PC Review


Reply
Thread Tools Rate Thread

Changing DefaultValue of a ComboBox at Runtime

 
 
David C. Holley
Guest
Posts: n/a
 
      20th Feb 2005
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
 
Reply With Quote
 
 
 
 
John Nurick
Guest
Posts: n/a
 
      20th Feb 2005
Have you experimented with the form's Repaint and Refresh methods, or
perhaps with requerying the comboboxes?

On Sun, 20 Feb 2005 00:26:10 -0500, "David C. Holley"
<(E-Mail Removed)> wrote:

>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


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      20th Feb 2005
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 Nurick wrote:
> Have you experimented with the form's Repaint and Refresh methods, or
> perhaps with requerying the comboboxes?
>
> On Sun, 20 Feb 2005 00:26:10 -0500, "David C. Holley"
> <(E-Mail Removed)> wrote:
>
>
>>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

>
>
> --
> John Nurick [Microsoft Access MVP]
>
> Please respond in the newgroup and not by email.

 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      20th Feb 2005
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 Nurick wrote:
> Have you experimented with the form's Repaint and Refresh methods, or
> perhaps with requerying the comboboxes?
>
> On Sun, 20 Feb 2005 00:26:10 -0500, "David C. Holley"
> <(E-Mail Removed)> wrote:
>
>
>>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

>
>
> --
> John Nurick [Microsoft Access MVP]
>
> Please respond in the newgroup and not by email.

 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      20th Feb 2005
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 Nurick wrote:
> Have you experimented with the form's Repaint and Refresh methods, or
> perhaps with requerying the comboboxes?
>
> On Sun, 20 Feb 2005 00:26:10 -0500, "David C. Holley"
> <(E-Mail Removed)> wrote:
>
>
>>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

>
>
> --
> John Nurick [Microsoft Access MVP]
>
> Please respond in the newgroup and not by email.

 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      20th Feb 2005
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

David C. Holley wrote:
> 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 Nurick wrote:
>
>> Have you experimented with the form's Repaint and Refresh methods, or
>> perhaps with requerying the comboboxes?
>>
>> On Sun, 20 Feb 2005 00:26:10 -0500, "David C. Holley"
>> <(E-Mail Removed)> wrote:
>>
>>
>>> 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

>>
>>
>>
>> --
>> John Nurick [Microsoft Access MVP]
>>
>> Please respond in the newgroup and not by email.

 
Reply With Quote
 
John Nurick
Guest
Posts: n/a
 
      20th Feb 2005
On Sun, 20 Feb 2005 10:27:51 -0500, "David C. Holley"
<(E-Mail Removed)> wrote:

>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?

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox defaultvalue changes Rucus Microsoft Access Forms 6 4th Feb 2008 11:29 PM
Change DefaultValue in a Table using a combobox ion a form ...how? =?Utf-8?B?U2lsdmlv?= Microsoft Access Forms 5 20th Oct 2006 06:09 PM
Changing ColumnWidths (ComboBox) at runtime hufflehuffle@west.de Microsoft Access Form Coding 2 2nd Jan 2006 02:25 PM
Changing the ListRowSource of a ComboBox at runtime in a DAP Sebas Microsoft Access 1 10th Aug 2004 04:30 AM
DefaultValue for ComboBox Robin Microsoft Access Form Coding 2 22nd Mar 2004 10:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:49 AM.