Change form control format in code

A

Ayo

I am trying to use this code to change the format of a combobox from Number
to Text:
Me.cmbProjectNumber.Format="Text"
but I am having a proplem doing this. I would like to know if the is a
better way to do this. Thank you.
 
S

Steve Schapel

Ayo,

You do not mention the nature of the problem. But "Text" is not one of
the valid options for the Format property of a combobox. I think you
probably need to do like this instead:
Me.cmbProjectNumber.Format=""
 
A

Ayo

I have a combobox with a label. When the label is "Project Number", the
values in the cmbbox are Numbers and when the label is "Site ID Number" the
values in the cmbbox are texts, alphanumeric.
What I want to be able to do is set the format of the combobox to text when
the label is "Site ID Number". Is this possible?
Thanks.
 
S

Steve Schapel

Ayo,

I believe I have already suggested a solution. Did you try what I gave
you in my earlier reply? What happened?
 
A

Ayo

I got the same error message. It said I was trying to input a ttext into a
number field or my nummber is to large for the field setting.
 
S

Steve Schapel

Ayo,

Can you copy/paste the whole of the code here - I mean the code that is
producing the error. Maybe someone will be able to spot a clue as to
what is going wrong. Thanks.
 
A

Ayo

Here is the code:
Private Sub frmSelectLevel_Click()
Me.cmbProjectNumber.Enabled = True
Select Case Me.frmSelectLevel
Case 1
Me.lblCombobox.Caption = "Project Number:"
Me.cmbProjectNumber.RowSource = "SELECT DISTINCT [Project
Number] FROM [Inscope Table] ORDER BY [Project Number];"
Me.cmbProjectNumber = Null
Me.cmbProjectNumber.Requery

Me.cmbTaskNumber.RowSource = "SELECT DISTINCT [Task Number] FROM
[Inscope Table] ORDER BY [Task Number];"
Me.cmbTaskNumber = Null
Me.cmbTaskNumber.Requery
Case 2
Me.lblCombobox.Caption = "Site ID Number:"
Me.cmbProjectNumber.Format = ""
Me.cmbProjectNumber.RowSource = "SELECT DISTINCT [National Site
ID] FROM [Inscope Table] ORDER BY [National Site ID];"
Me.cmbProjectNumber = Null
Me.cmbProjectNumber.Requery

Me.cmbTaskNumber.RowSource = "SELECT DISTINCT [Task Number] FROM
[Inscope Table] ORDER BY [Task Number];"
Me.cmbTaskNumber = Null
Me.cmbTaskNumber.Requery
End Select
End Sub
 
S

Steve Schapel

Ayo,

Since you are explicitly setting the Format of the combobox for the "1"
case, you probably should also be setting it for the "2" case. I guess
it would be:
Me.cmbProjectNumber.Format = "General Number"

But is that when you get the error message, when you click the
frmSelectLevel? Or what is frmSelectLevel? If it is an Option Group,
it would be better to have this code on its After Update event rather
than the Click event.

Another option you might consider, instead of trying to toggle the
properties of a single combobox to serve 2 such different functions,
would be to make 2 separate comboboxes, and then your code on the
frmSelectLevel would simply toggle their Visible property.
 
A

Ayo

Thanks for all the help Steve.

Steve Schapel said:
Ayo,

Since you are explicitly setting the Format of the combobox for the "1"
case, you probably should also be setting it for the "2" case. I guess
it would be:
Me.cmbProjectNumber.Format = "General Number"

But is that when you get the error message, when you click the
frmSelectLevel? Or what is frmSelectLevel? If it is an Option Group,
it would be better to have this code on its After Update event rather
than the Click event.

Another option you might consider, instead of trying to toggle the
properties of a single combobox to serve 2 such different functions,
would be to make 2 separate comboboxes, and then your code on the
frmSelectLevel would simply toggle their Visible property.
 
Top