Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2004, 03:36 PM
Registered User
 
Join Date: Jan 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble with SubForms

I am having trouble with a new subform in a program that has been working just fine. A requirement changed which I felt could be solved by adding this subform (and an underlying Table - "tblSalesRepOrders").

The name of the Main Form is "frmOrders". There are already 3 "tabs" on this form which record the "order details". The new subform is titled "fsubSalesReps". The previous screen could accommodate 1 rep per order; this new program allows more than 1 rep to receive credit for an order.

The underlying query of "fsubSalesReps" is is based primarily on "tblSalesRepOrders". The Primary Key of this table is "Territory Code" + "Order#". On "frmOrders" (1) a customer is selected from a list (or created); each customer is assigned a Territory Code. Each Territory Code points to a Sales Rep in "tblSalesReps". (2) The Order# is entered. (3) The subform "fsubSalesReps" is entered and 1 or more sales reps are credited with the order. The 1st control is "TerritoryCode" which is a combo box.

Question #1: How can I create a default Territory Code (i.e. the one that is already assigned to the Customer) that displays on the subform? When I have been able to get this to occur, it appears that the "TerritoryCode" control is still reporting a "null" because I receive the message that a Primary Key cannot include a null field.

Question #2: How do I move the necessary data to controls on this subform (and ultimately to "tblSalesRepOrders"). For example, the commission rate from "tblSalesReps" needs to be saved.

The problem "seems to be" that when the cursor is in one Form (e.g. "frmOrders") it does not see the controls in the other Form (e.g. "fsubSalesReps"). (I have been trying to do this without DAO because I think I should be able to.)

Thanks for your help.



 
Old May 22nd, 2004, 12:50 PM
Authorized User
 
Join Date: Oct 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Keith,
What I have used in the past, but not for a primary key, is the "OnCurrent" event of a form.
eg; If Me.newRecord Then
     Primary Key = Me.TerritoryCode & Me.Order#
     End If

Now the problem here is that it seems the "TerritoryCode" & Order#" are designated after the fact.
Assuming I'm correct, In the code I showed above, you can give the primary key, an obviously wrong number "000000", just to bypass the error & alert the user that it has not been entered properly.
Or create an error routine which "resumes" if the error (Err.Number) you mentioned above, occurs.
Hope this helps, good luck!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Forms/SubForms JezLisle Access VBA 2 July 23rd, 2007 08:59 AM
Subforms 150563a Access 1 June 29th, 2007 04:57 AM
subforms ajmil11 Access 2 January 19th, 2006 11:16 PM
Subforms V Access VBA 1 April 21st, 2004 11:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.