?
Solved

Filter propert on form uses form textboxes nopt table field names

Posted on 2011-03-24
2
Medium Priority
?
238 Views
Last Modified: 2012-05-11
I have two database systems.

In one when the user applies a filter to a form the filter property on the form is set using the forms control names
e.g. ([frmContacts].[contactTelephoneNumber] Like "*N/A*")

In the other the filter property is set using the table names
e.g.([tblClient].[CL_Name] Like "*Pa*")

Both forms are based on a query of one table - one the contact table one  the client. table.
Remember both filters are set from the ribbon - none of my code.

I need the filters to use the table names (so I can use the me.filter string in an sql command to append to a table e.g.

DoCmd.RunSQL "Insert Into ContactsForMailMerge Select * From tblClient Where " & Screen.ActiveForm.Filter

This works filne when the filter uses the table names but obviously not when it uses the form names.


Why are the two forms using different syntax for the same property?
By the way if I copy the one using form names to the other database - it still uses form names.


Thanks
Lou
0
Comment
Question by:Louverril
2 Comments
 
LVL 24

Accepted Solution

by:
Bitsqueezer earned 2000 total points
ID: 35213147
Hi,

I think it depends on the RecordSource you used in the form. If the field you filters is 1:1 a table field then the filter will use the table field. If the field is a calculated field in the query (not in the form, that cannot be filtered) like "SELECT [Field1] & [Field2] AS Field3..." then there is no field of the table which can be used and so Access uses the form field instead. Of course a field like this can also not be used to insert a value with an INSERT command - because there is no "Field3" in the table to SELECT. You must use the same method to select the data from the underlying tables like used in the RecordSource. You should be able to use "SELECT [Forms]![frmContacts].[contactTelephoneNumber]..." but only if the form is loaded.
But as you can see in the filter expression, there is no "Forms!" prefix and so it will be interpreted as query parameter which must be entered.
If you want to use your INSERT command you must make sure that all fields of the form are based directly on table fields or you must write a text parser which analyzes the filter string and "repairs" it. Not an easy job as there are a lot of possible filter variants.

Cheers,

Christian
0
 

Author Comment

by:Louverril
ID: 35244244
Thanks for that - will check it out in the next couple of days - O got sidetracked with something else but tomorrow this is back as priority 1.

I think I will have to use me.recordsetclone and create a table.

thanks Lou

0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question