keri wrote:
Quote:
Hi and thanks,
>
I have no experience of subforms so have been reading avidly. My
problem is going to be the search fields - I will need at least 5 - and
how to filter the sub form based on what is entered in these fields. I
do not know how to join two or more filter codes together (sorry for
the terrible language use there but i can't hink of a better way to say
it!).
Form/Subform help.
First, create the subform. Use the Form Wizard to build the form. As
you step thru the wizard you'll be asked if you want it to be Columnar,
Tabular, or Datasheet. Select datasheet.
Now select Forms/New/Design. Here you have 3 sections; header, detail,
and footer. Put the search stuff in the header and Select buttons in
the footer. From the toolbar (toolbox icon) select the Subform option.
Drop it into the detail section. There is nothing to link the main
form to the subform so if prompted select None.
Explanation: Let's say you had an order form with order items. The
order form would be the main form. The order items would be the
subform. The link between each form is the OrderID.
How to sort a subform. In your query you can sort the records the way
you want. You can also change the sort via code.
Me.OrderBy = "LastName" 'this sets the field to sort on
Me.OrderByOn = True 'this "turns on" the sort
How to filter a subform. You can filter records out via the
recordsource. You might have a query like
Select * From Orders Where Customer = ""Smith""
You could also have the recoursource be
Select * From Orders
and filter manually via code. Ex:
Me.Filter = "Customer = ""Smith"""
Me.FilterOn = True
To remove a filter
Me.FilterOn = False
To remove a sort
Me.OrderBy = False
The sort/filter methods I did above were for the form you are in and
referencing. If you are setting the filter or sort from the main form
and you want to filter data in the subform you need to reference the
subform. If the main form is called MainForm and the subform is called
SubForm then
Forms!MainForm!Subform.Form.OrderBy = "Customer"
Forms!MainForm!Subform.Form.OrderByOn = True
Albert provide you a link to some Access templates at MS. The reason he
provided the templates link is
1) the work has been done.
2) you can import the form templates into your own database
This does not mean the templates are complete. They are simply a
starting point and you can modify them at will.
BTW, examples of multiple sort fields, multiple filters
Me.OrderBy = "LastName, OrderDate DESC"
Me.Filter = "LastName = 'Smith' And OrderDate #1/1/2007#"
In the sort above, I have 2 sort fields. The OrderDate fields is
ordering in descending order. The filter example is basically the Where
clause of in a SQL statement but it excludes the word Where.
Quote:
Further to this (when that part is working) once I have selected the
correct record I presume I will need to refer to this as an active
record or something to use thins information in fields in my main form.
In my first post, I was thinking you'd want to find a customer record in
the appointment/call form. So you'd have a button to find the customer
and return the value of the customerid to the calling form.
Here's a tip. When you create a table, create an autonumber field and
make it the primary key. This key may or may not be sequential so don't
use it for a sequential numbering scheme. As you develop in Access,
you'll be glad you created the table key as an autonumber.
I think that you are still a bit new to Access and need some further
education. I would highly recommend you go to a bookstore and see if
they have any Visual type books. You can go thru them quickly and get
an idea of the environment you are working in. I would also get an MS
Step-By-Step book on Access...if you DO the exercises you'll feel
comfortable with coding events.
If at all possible, learn how to code. Don't bother with macros if you
want to be serious. Study the messages here and at some point all this
stuff will become clear. Also, goto
http://www.mvps.org/access.
There's lot of solutions to common problems there. Study them and
you'll get up to speed quicker.
Quote:
>
My apologies for seeming a real beginner here but I thought I had
cracked the basics then along comes the use for a subform!
Everybody here was a beginner at one time or another.
You will appreciate subforms, the simplicity of creating and ease of
implementation, if you ever have a problem where you need to present
something like an order and all the associated order items. You simply
need some practice.
Quote:
>
salad wrote:
>
Quote:
>>keri wrote:
>>
Quote:
>>>Thanks everybody for your answers.
>>>I should have learnt that by now if I explain what I want my database
>>>to achieve you will all help with the best way of doing this. I am
>>>still struggling with part of my design and have narrowed it down to 2
>>>ways of doing this so.....
>>>
>>>My user needs to be able to add an appointment or record a call or
>>>perform another action they have made with customers.
>>>I have a customers table which holds over 1200 customers. I want a
>>>simple way for my users to perform an action on the customer.
>>>
>>>Choice 1.
>>>The user opens a form (to record an appointment or a call or another
>>>action) on which there is a button which opens the customers table.
>>>They can then search this table via any field and select the customer
>>>they want. This would take them back to the form with the customer
>>>fields populated from the selection on the customer table.
>>
>>I might consider creating a form/subform to find a customer. 1200
>>customer records is getting a bit large for a combo dropdown and most
>>likely your customer set is going to do nothing but grow.
>>
>>In search form header provide a method to search for the customer. Is
>>it necessary to search on every field? Most likely not. You would most
>>like search on name, address, phone number, customerid, acct number, or
>>ssn or something that makes your search result unique. You could
>>provide a listbox, option group, or dropdown to select the search field.
> In a text box, allow the op to enter the item to search for. Some
>>records may be difficult to find. You may have partial information to
>>search for a customer and require a more "manual" find. So you may want
>>to provide a filter. You might want to filter on state or city or area
>>code to limit the list. So you might select to filter on city and enter
>>"Dallas" and only customers in Dallas are presented.
>>
>>The subform would contain, either as a datasheet or continuous form, the
>>fields you would want to display when finding the customer. You could
>>provide a Dbl-Click event that selects the customer.
>>
>>In the form footer you could have a couple of command buttons; Select
>>and Exit. If select, that current customer record is selected (just
>>like the Dbl-Click. If exit, you abandoned the search.
>>
>>What happens if the customer does not exist in this table? You can also
>>have a button in the footer to call a form to add a customer.
>>
>>When the user presses the find button, the search form could be opened
>>up as a dialog/modal form. When you select the record, you could stuff
>>the customer id in the calling form
>> Forms!CallingForm!CustomerID = Me.CustomerID
>>and then close the search form. Another method could be if you cancel
>>the search, you close the search form. If you select a customer record,
>>you make the form hidden.
>> Me.Visible = False
>>and this will return control back to the calling form. This would
>>continue execturing the code following the code line that opened the
>>form. You could check to see if the search form is still loaded. If it
>>is, get the customer id and close the search form.
>>
>>I would put the find button on your appointments form.
>>
>>
Quote:
>>>Choice 2. The user opens the customer table and selects the customer
>>>they want to record an appointment or call with. They can then click a
>>>button on the toolbar that will open the form (eg appointments) and
>>>populate the customer fields with the customer details from the
>>>selection in the accounts table.
>>>
>>>I can't decide which option is best to use or even which is possible!
>>>
>>>Thanks everyone.
>>>
>
>