473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

VBA and Filter Question

Form name to filter = frmSortFor
Filter based on list box from frmTest= lstSortFor
Form containing list box = frmTest
Field (CompCodes) data format = "PM SM TS EW WA"

I have a database that I want to filter a form (frmSortFor) useing the field (CompCodes). I need to find the records that match any of the 2 letter codes that I select on the list box. When i use the code listed below i get an runtime error :

"Microsoft Access can't Find the field 'FrmSortFor' referred to in your expression.".

I am pretty sure it is the way I have my filter syntax is set up but have not been able to find a good example as to what it should look like. Currently the filter data that is generated by the code and is stored in the variable SortFor looks like this:

""Forms!FrmSortFor!CompCodes= Like "*5M*" or Forms!FrmSortFor!CompCodes= Like "*HW*" or Forms!FrmSortFor!CompCodes= Like "*QM*""

Form name to filter = frmSortFor
Filter based on list box name = lstSortFor
Form containing list box = frmTest
Field (CompCodes) data format = "PM SM TS EW WA"


Current Software
- Access 97
- Win XP

Database
Format of Data in [CompCodes] field "PM SM TS EW WA"


Private Sub cmdPullFilteredRecords_Click()

Dim SortFor As String
Dim F As Variant

' Build Criteria string from selected Items in list box

SortFor = ""

For Each F In Me![lstSortFor].ItemsSelected

If SortFor <> "" Then
SortFor = SortFor & " or "
End If
SortFor = SortFor & "Forms!FrmSortFor!CompCodes=" & " Like " & Chr(34) & "*" & Me![lstSortFor].ItemData(F) & "*" & Chr(34)
Next F

' Open and Filter a form based on [CompCodes] field in frmSort for

DoCmd.OpenForm "frmSortFor", acFormDS
Form!FrmSortFor.Filter = SortFor
Form!FrmSortFor.FilterOn = True

End Sub


Any help would be greatly appretiated. Thank you
Jan 15 '08 #1
3 1977
What is the format that a filter statement should be written in? I can't seem to find it anywhere.

Thanks
Jan 16 '08 #2
QVeen72
1,445 Expert 1GB
Hi,

You cannot write in Form Control names in double codes ..

Any way try this :
Expand|Select|Wrap|Line Numbers
  1. SortFor = SortFor & "CompCodes Like " & Chr(34) & "*" & Me![lstSortFor].ItemData(F) & "*" & Chr(34)
  2.  
Check you want to search for "List" or "ItemData"....?

Regards
Veena
Jan 16 '08 #3
Well the items i am searching for are in 3 multi select list boxes. List box 1 is to find all records containing the codes selected. Then List box 2 takes those records and sorts out specific codes and list box 3 finds specific codes within those records. I have not worked with VBA much and what I know is self taught so I have quite a few holes in my knowlege. I think useing a recordset would do it but have not found any real good information on the internet to explain how to use that.


so Like *ListBox1*, Not Like *ListBox2* and Like *ListBox3*
Jan 21 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a variable length list of associated values after...
1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
8
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and...
4
by: Keith | last post by:
A2003, XP Pro. I'm in the middle of designing a form to act as a custom filter, like a very basic 'filter by form'. It has two sets of combos, those on the left are to choose the field name(s)...
2
by: cefrancke | last post by:
I have a form (no underlying record set) that has two separate sub-forms on it. Each sub-form has data from two different tables. Above each sub-form there is one unbound combo box with a SQL...
2
by: AAJ | last post by:
I know this sounds nuts, but how do I remove the following filter from a Object Datasource that looks at my business layer... ODSDefaultUserProfiles.FilterExpression = "AllowedWebPage = '" +...
9
by: dee | last post by:
I'd like to filter by the following criteria: left(LeadDisposition,3) = "Sit" AND Appt_Date = Text767 I have no idea how to do this. Appreciate help.
15
by: scatterbrain | last post by:
I'm trying to create a popup form so that my peers have and easy way to filter information by 4 categories: Presenter, Evaluator, Date, or Topic. All this information is stored in my Data table and I...
4
by: Twayne | last post by:
Hi, I've been playing with ' if(!filter_var($email, FILTER_VALIDATE_EMAIL)) ' on my server and it seems to be working 100%. Pretty handy. Any ideas where I could find a summary of the e-mail...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.