Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2005

Tip: Looking for answers? Try searching our database.

Queries and Combo Box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AndyEduardo - 24 Nov 2005 17:39 GMT
Hello!

I have a form to make the invoice. It has one cbo (Information abou
Clients) and inside this form I have a subform whit a cbo (Products)
One client can to buy several products by an agreement.

I made a query to view the clients related with the products and
established this criteria
in the Clients field.....=Forms.....CboClients

I want this:

When I expand the second cbo, the list of products shows just th
products in the agreement based in the client of first cbo...

Thanks for your help

I apologize about mi english, I'm not a english-speake

--
AndyEduard
Allen Browne - 25 Nov 2005 01:21 GMT
Andy, it sounds like you have an agreement with a client regarding products,
and you want to prevent the user from sellling products that are not covered
in an agreement.

If so, you will need an Agreement table that defines which products are
associated with which clients. The table will have fields:
   ClientID    foreign key to Client.ClientID
   ProductID  foreign key to Product.ProductID
You can therefore limit RowSource of the combo to products for the client.

This example goes in the AfterUpdate event of the ClientID combo in the main
form. Adjust the code to suit. The Current event of the main form needs to
call the same code, so it reloads the combo as you move record in the main
form.

Private Sub ClientID_AfterUpdate()
   Dim strWhere As String
   Const strcStub = "SELECT Agreement.ProductID, Product.ProductName FROM
Agreement INNER JOIN Product ON Agreement.ProductID = Product.ProductID
WHERE "
   Const strcTail = " ORDER By ProductName;"

   If IsNull(Me.ClientID) Then
       strWhere = "(False)"
   Else
       strWhere = "ClientID = " & Me.ClientID
   End If

   Me.[YourSubformNameHere].Form!ProductID.RowSource = strcStub & strWhere
& strcTail
End Sub
Private Sub Form_Current()
   Call ClientID_AfterUpdate
End Sub

Notes:
====
1. If ClientID is a Text field (not a Number field), you need extra quotes:
       strWhere = "ClientID = """ & Me.ClientID & """"

2. If the ProductID combo's bound column is zero-width, it will appear blank
if it contains a value that is not in the list. For example, if you no
longer have an agreement to sell product 99 to a client, but you are looking
at one of their old orders where you did supply 99 to them, the combo won't
have the name for that product in its list, and so it will show a blank. (If
the ProductID's bound column is NOT zero-width, it might be more efficient
to use the Enter event of the ProductID combo instead of the events
suggested above.)

3. If you are not sure how to get the SQL statement right, create a mock
query into the 2 tables, and use any literal number in the Criteria under
your ClientID. Then switch to SQL View (View menu, in query design) for an
example.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Hello!
>
[quoted text clipped - 14 lines]
>
> I apologize about mi english, I'm not a english-speaker
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.