B
BruceM
I have a table in which a unique value is in the format S-07-01. The number
is generated automatically. "S" is the department code, 07 is the year, and
01 is the first record this year for that department. By the way, the date
the record was started is also stored, so in a sense the 07 is redundant,
but I decided not to worry about that. I stored the literal text value
S-07-01.
I decided not to store the department name, since it could be determined
from the identifying number ("S" stands for "Sales", for instance).
However, this is causing problems when I try to filter the records. Some
department codes are two-letters ("SH" is "Shipping"), so there could be
both S-07-01 and SH-07-01.
I am trying to filter by using a combo box with the department code and
department name as the two columns in the row source:
S Sales
SH Shipping
Literal values produce the desired result in a command button click event:
Me.Filter = "Left([MyNumber], 1) = ""S"""
Me.FilterOn = Not Me.FilterOn
However, I have not found a way to use variables instead of the literal
values (this code in the combo box After Update event):
Private Sub cboFilter_AfterUpdate()
dim lngDept as Long, strFilter as String
lngDept = Len(Me.cboFilter) ' the length of the department code
Me.Filter = Left([MyNumber],lngDept) = Me.cboFilter
' If "Sales" was selected from cboFilter, this is intended to be:
' Me.Filter = "Left([MyNumber],1) = ""S"""
Me.FilterOn = Not Me.FilterOn
End Sub
I have not been able to find an arrangement of quote marks that will get
this to do anything except prompt for parameters. I realize the code will
not make a distinction between "S" and "SH" as department codes, but this is
irrelevant for now since the code doesn't do anything at all.
Of course, if I had stored the department this would be pretty simple. The
database is in the development stages, so there is no problem with going
back to add the field, if that is the cleanest way to solve this problem.
is generated automatically. "S" is the department code, 07 is the year, and
01 is the first record this year for that department. By the way, the date
the record was started is also stored, so in a sense the 07 is redundant,
but I decided not to worry about that. I stored the literal text value
S-07-01.
I decided not to store the department name, since it could be determined
from the identifying number ("S" stands for "Sales", for instance).
However, this is causing problems when I try to filter the records. Some
department codes are two-letters ("SH" is "Shipping"), so there could be
both S-07-01 and SH-07-01.
I am trying to filter by using a combo box with the department code and
department name as the two columns in the row source:
S Sales
SH Shipping
Literal values produce the desired result in a command button click event:
Me.Filter = "Left([MyNumber], 1) = ""S"""
Me.FilterOn = Not Me.FilterOn
However, I have not found a way to use variables instead of the literal
values (this code in the combo box After Update event):
Private Sub cboFilter_AfterUpdate()
dim lngDept as Long, strFilter as String
lngDept = Len(Me.cboFilter) ' the length of the department code
Me.Filter = Left([MyNumber],lngDept) = Me.cboFilter
' If "Sales" was selected from cboFilter, this is intended to be:
' Me.Filter = "Left([MyNumber],1) = ""S"""
Me.FilterOn = Not Me.FilterOn
End Sub
I have not been able to find an arrangement of quote marks that will get
this to do anything except prompt for parameters. I realize the code will
not make a distinction between "S" and "SH" as department codes, but this is
irrelevant for now since the code doesn't do anything at all.
Of course, if I had stored the department this would be pretty simple. The
database is in the development stages, so there is no problem with going
back to add the field, if that is the cleanest way to solve this problem.