How can I set the format of a control in code

  • Thread starter Thread starter Ayo
  • Start date Start date
A

Ayo

For example I am try to set the format of a comboBox that can take many
values but I want to be able to set the format for each value.

If Me.cmbTrackerFields.Value = "Denied" Then
Me.Form.Filter = "[Invoice Tracker].[" & Me.cmbTrackerFields.Value &
"]='" & Me.cmbFieldValues.Value & "'"
Me.Form.FilterOn = True

I want to be able to set the format for
Me.cmbFieldValues.Value to "Yes/No".
I tried this
Me.cmbFieldValues.Format = "Yes/No"
but that didn't work.
Any ideas?
Thanks.
 
Me.cmbFieldValues.Format = "Yes/No"
Should work, but might not if the control has focus.
 
Ayo,
Check out the Format Function in Access Help...
If a field named Active is defined as boolean...
= Format(Active,"Yes/No")
would yield "No" for 0 and "Yes" for -1.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
Thanks George.
But what do you think is wrong with this? I can't get it to work, I keep
getting "You canceled the previous operation" error message.

If Me.cmbTrackerFields.Value = "Approved" Then
Me.cmbFieldValues.Format = "Yes/No"
Me.Form.Filter = "[Invoice Tracker].[" & Me.cmbTrackerFields.Value &
"]='" & "Yes" & "'"
Me.Form.FilterOn = True

George Nicholson said:
Me.cmbFieldValues.Format = "Yes/No"
Should work, but might not if the control has focus.

--
HTH,
George


Ayo said:
For example I am try to set the format of a comboBox that can take many
values but I want to be able to set the format for each value.

If Me.cmbTrackerFields.Value = "Denied" Then
Me.Form.Filter = "[Invoice Tracker].[" & Me.cmbTrackerFields.Value
&
"]='" & Me.cmbFieldValues.Value & "'"
Me.Form.FilterOn = True

I want to be able to set the format for
Me.cmbFieldValues.Value to "Yes/No".
I tried this
Me.cmbFieldValues.Format = "Yes/No"
but that didn't work.
Any ideas?
Thanks.
 
you might try:

strFilter = "[Invoice Tracker].[" & Me.cmbTrackerFields.Value &
"]= " & cbool(Me.cmbFieldValues.Value)
Me.Form.Filter = strFilter

put a breakpoint on the last line. When the breakpoint is reached, type the
following in the Immediate window:
? strFilter
and analyze the result. Does it make sense? Keep in mind that if the field
you are filtering on is defined as a Yes/No field, it expects True, False, 0
or -1 (without quotes) as Filterable values.

Where is this code running? In an Event? Which one? If its running in the
BeforeUpdate event of a bound control, move it to AfterUpdate. You can't
re-change the value of a control from BeforeUpdate (which changing the
Form.Filter will do).

--
HTH,
George


Ayo said:
Thanks George.
But what do you think is wrong with this? I can't get it to work, I keep
getting "You canceled the previous operation" error message.

If Me.cmbTrackerFields.Value = "Approved" Then
Me.cmbFieldValues.Format = "Yes/No"
Me.Form.Filter = "[Invoice Tracker].[" & Me.cmbTrackerFields.Value
&
"]='" & "Yes" & "'"
Me.Form.FilterOn = True

George Nicholson said:
Me.cmbFieldValues.Format = "Yes/No"
Should work, but might not if the control has focus.

--
HTH,
George


Ayo said:
For example I am try to set the format of a comboBox that can take many
values but I want to be able to set the format for each value.

If Me.cmbTrackerFields.Value = "Denied" Then
Me.Form.Filter = "[Invoice Tracker].[" &
Me.cmbTrackerFields.Value
&
"]='" & Me.cmbFieldValues.Value & "'"
Me.Form.FilterOn = True

I want to be able to set the format for
Me.cmbFieldValues.Value to "Yes/No".
I tried this
Me.cmbFieldValues.Format = "Yes/No"
but that didn't work.
Any ideas?
Thanks.
 
Thanks Al.
I saw that the first time I tried to run the filter but I can get it to work

Private Sub cmdFilter_Click()
If Me.cmbTrackerFields.Value = "Approved" Then
Me.Form.Filter = "[Invoice Tracker].[" & Me.cmbTrackerFields.Value &
"]='"
& Me.cmbFieldValues.Value & "'"
Me.Form.FilterOn = True
End if

Me.cmbFieldValues.Value is a Yes/No field. But on the comboBox, it' show 0
and -1 which is fine but when I click the cmdFilter button, I get an error
message. That why I am trying the:
Me.cmbTrackerFields.Value = "Approved" Then
Me.cmbFieldValues.Format = "Yes/No"
Me.Form.Filter = "[Invoice Tracker].[" & Me.cmbTrackerFields.Value &
"]='"
& Me.cmbFieldValues.Value & "'"
Me.Form.FilterOn = True

And this is not doing any better.

Al Campagna said:
Ayo,
Check out the Format Function in Access Help...
If a field named Active is defined as boolean...
= Format(Active,"Yes/No")
would yield "No" for 0 and "Yes" for -1.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."

Ayo said:
For example I am try to set the format of a comboBox that can take many
values but I want to be able to set the format for each value.

If Me.cmbTrackerFields.Value = "Denied" Then
Me.Form.Filter = "[Invoice Tracker].[" & Me.cmbTrackerFields.Value
&
"]='" & Me.cmbFieldValues.Value & "'"
Me.Form.FilterOn = True

I want to be able to set the format for
Me.cmbFieldValues.Value to "Yes/No".
I tried this
Me.cmbFieldValues.Format = "Yes/No"
but that didn't work.
Any ideas?
Thanks.
 

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

Back
Top