How to delete the value of combo box programmly

  • Thread starter Thread starter SG
  • Start date Start date
S

SG

Hi,

There is a combo box on the form1, row source type is value list , row
source is "<All>";"Atln";"East";"Central";"West"

How can I delete the at least 2 values from this list programmly.

Thanks,
Sarah
 
SG,

Lets assume you want to remove "Atln" and "Central"

strFix = forms!MyForm!MyCombo.RowSource
strFix = Replace(strFix,"""Atln"";","")
strFix = Replace(strFix,"""Central"";","")
forms!MyForm!MyCombo.RowSource = StrFix

This works whether the rowsource is a list or an SQL statement. If you are
using a query, then you would modify the query's SQL property much the same
way.
 
Hi Klatuu,

Thanks for your quick response. I wanted to ask two questions:
1. Do I claim strFix as string?
2. I tried your code, vb complains the following code, saying, "run time
error 2450', can't find the form 'selectregion form' in the macro expression
or vb code", but the form exists.

strfix = [Forms]![SelectRegion Form]![comboRegion].RowSource

Can you please help me with this?

Thanks so much again,
Sarah
 
1. Yes
2. Was the form open at the time? The code looks okay, but not having
everything in front of me, I would check for spelling errors, etc.

Also, I notice there is a space in the form's name. It is always better to
avoid using spaces in any naming. It can create problems.

SG said:
Hi Klatuu,

Thanks for your quick response. I wanted to ask two questions:
1. Do I claim strFix as string?
2. I tried your code, vb complains the following code, saying, "run time
error 2450', can't find the form 'selectregion form' in the macro expression
or vb code", but the form exists.

strfix = [Forms]![SelectRegion Form]![comboRegion].RowSource

Can you please help me with this?

Thanks so much again,
Sarah
Klatuu said:
SG,

Lets assume you want to remove "Atln" and "Central"

strFix = forms!MyForm!MyCombo.RowSource
strFix = Replace(strFix,"""Atln"";","")
strFix = Replace(strFix,"""Central"";","")
forms!MyForm!MyCombo.RowSource = StrFix

This works whether the rowsource is a list or an SQL statement. If you
are
using a query, then you would modify the query's SQL property much the
same
way.
 
Thanks Klatuu again. Yes, the name of the form has a space. It's hard to
change it right now because so many codes are involved. I will try your
suggestion.

Appreciate,
Sarah
Klatuu said:
1. Yes
2. Was the form open at the time? The code looks okay, but not having
everything in front of me, I would check for spelling errors, etc.

Also, I notice there is a space in the form's name. It is always better
to
avoid using spaces in any naming. It can create problems.

SG said:
Hi Klatuu,

Thanks for your quick response. I wanted to ask two questions:
1. Do I claim strFix as string?
2. I tried your code, vb complains the following code, saying, "run time
error 2450', can't find the form 'selectregion form' in the macro
expression
or vb code", but the form exists.

strfix = [Forms]![SelectRegion Form]![comboRegion].RowSource

Can you please help me with this?

Thanks so much again,
Sarah
Klatuu said:
SG,

Lets assume you want to remove "Atln" and "Central"

strFix = forms!MyForm!MyCombo.RowSource
strFix = Replace(strFix,"""Atln"";","")
strFix = Replace(strFix,"""Central"";","")
forms!MyForm!MyCombo.RowSource = StrFix

This works whether the rowsource is a list or an SQL statement. If you
are
using a query, then you would modify the query's SQL property much the
same
way.


:

Hi,

There is a combo box on the form1, row source type is value list , row
source is "<All>";"Atln";"East";"Central";"West"

How can I delete the at least 2 values from this list programmly.

Thanks,
Sarah
 
Back
Top