Synchronize Combo Boxes

C

Confused

I'm trying to synchronize CboEmployeeName with CboTitles (these are bound
combo boxes) on a subform, which is a continuous form that has Customer
Names and to whom they are assigned. I.e:

Customer A Account Manager John Smith
Operation Manager Bob Jones
Order Mangager Sally Sue
Test Manager Sandy Shores
etc.

I have this statement on the row source of CboEmployeeNames

SELECT DISTINCT Employees.EmployeeID, Employees.FullName, Employees.Title
FROM Employees WHERE
(((Employees.Title)=Forms!CLECS2MainForm![QryEmployeeAssignments
subform1]!cbotitles)) ORDER BY Employees.FullName;

I have a requery event procedure on CboTitles to keep the combos
synchronized.

The problem is that it only allows me to view or add one title and employee
rather than four. I.e. it only allows me to view/add John Smith Account
Manager per customer. And not in turn add Operation Manager Bob Jones. Is
there a way to view/add multiple selections per customer?

Please help!
 
T

tina

so one customer may be assigned to many employees, and presumably one
employee may have many customer assignments. that's a many-to-many
relationship. to model that relationship in Access you need *three* tables:
tblCustomers, tblEmployees, tblCustomerEmployees (or tblEmployeeCustomers,
same difference). tblCustomers lists all customers, tblEmployees lists all
employees, and tblCustomerEmployees lists every customer assigned to every
employee, using the primary key fields of both those tables as foreign key
fields. if CustomerA is assigned to 4 employees, there will be 4 CustomerA
records in tblCustomerEmployees - one for each assigned employee. if
Employee12 has 17 customer assignments, there will be 17 Employee12 records
in tblCustomerEmployees - one for each assigned customer.

recommend you read up/more on relational design principles, so you'll
understand how to build correct tables/relationships. for more information,
see http://home.att.net/~california.db/tips.html#aTip1.

hth
 
C

Confused

Your answer has nothing to do with the question that I posted.

There are adequate tables for each relationship. There are tblCustomers,
tblEmployees, tblCustomeremplyees. Moreover all of the data is normalized.

I am asking about how to synchronize combo boxes on a subform/continuous
form.

tina said:
so one customer may be assigned to many employees, and presumably one
employee may have many customer assignments. that's a many-to-many
relationship. to model that relationship in Access you need *three* tables:
tblCustomers, tblEmployees, tblCustomerEmployees (or tblEmployeeCustomers,
same difference). tblCustomers lists all customers, tblEmployees lists all
employees, and tblCustomerEmployees lists every customer assigned to every
employee, using the primary key fields of both those tables as foreign key
fields. if CustomerA is assigned to 4 employees, there will be 4 CustomerA
records in tblCustomerEmployees - one for each assigned employee. if
Employee12 has 17 customer assignments, there will be 17 Employee12 records
in tblCustomerEmployees - one for each assigned customer.

recommend you read up/more on relational design principles, so you'll
understand how to build correct tables/relationships. for more information,
see http://home.att.net/~california.db/tips.html#aTip1.

hth


Confused said:
I'm trying to synchronize CboEmployeeName with CboTitles (these are bound
combo boxes) on a subform, which is a continuous form that has Customer
Names and to whom they are assigned. I.e:

Customer A Account Manager John Smith
Operation Manager Bob Jones
Order Mangager Sally Sue
Test Manager Sandy Shores
etc.

I have this statement on the row source of CboEmployeeNames

SELECT DISTINCT Employees.EmployeeID, Employees.FullName, Employees.Title
FROM Employees WHERE
(((Employees.Title)=Forms!CLECS2MainForm![QryEmployeeAssignments
subform1]!cbotitles)) ORDER BY Employees.FullName;

I have a requery event procedure on CboTitles to keep the combos
synchronized.

The problem is that it only allows me to view or add one title and employee
rather than four. I.e. it only allows me to view/add John Smith Account
Manager per customer. And not in turn add Operation Manager Bob Jones. Is
there a way to view/add multiple selections per customer?

Please help!
 
K

kc-mass

Are there established teams in the assignments? That is if a customer is
assigned "John Smith" as Account Manager, does that customer then get "Bob
Jones", "Sally Sue" and "Sandy Shores" for the other roles or are the four
roles independent?

Kevin
 
T

tina

then your question isn't clear, and neither is your form setup.
The problem is that it only allows me to view or add one title and employee
rather than four.

that doesn't sound like a syncronization issue, it sounds like you can't
make multiple selections. from the context, i assumed you were trying to
select multiple items from a combobox droplist in a single record. so i
explained that you need a separate table, with multiple records, instead.
are you saying that the subform will only allow you to enter one *record*?
what happens when you try to enter a second record in the subform? more
info, please.

hth


Confused said:
Your answer has nothing to do with the question that I posted.

There are adequate tables for each relationship. There are tblCustomers,
tblEmployees, tblCustomeremplyees. Moreover all of the data is normalized.

I am asking about how to synchronize combo boxes on a subform/continuous
form.

tina said:
so one customer may be assigned to many employees, and presumably one
employee may have many customer assignments. that's a many-to-many
relationship. to model that relationship in Access you need *three* tables:
tblCustomers, tblEmployees, tblCustomerEmployees (or tblEmployeeCustomers,
same difference). tblCustomers lists all customers, tblEmployees lists all
employees, and tblCustomerEmployees lists every customer assigned to every
employee, using the primary key fields of both those tables as foreign key
fields. if CustomerA is assigned to 4 employees, there will be 4 CustomerA
records in tblCustomerEmployees - one for each assigned employee. if
Employee12 has 17 customer assignments, there will be 17 Employee12 records
in tblCustomerEmployees - one for each assigned customer.

recommend you read up/more on relational design principles, so you'll
understand how to build correct tables/relationships. for more information,
see http://home.att.net/~california.db/tips.html#aTip1.

hth


Confused said:
I'm trying to synchronize CboEmployeeName with CboTitles (these are bound
combo boxes) on a subform, which is a continuous form that has Customer
Names and to whom they are assigned. I.e:

Customer A Account Manager John Smith
Operation Manager Bob Jones
Order Mangager Sally Sue
Test Manager Sandy Shores
etc.

I have this statement on the row source of CboEmployeeNames

SELECT DISTINCT Employees.EmployeeID, Employees.FullName, Employees.Title
FROM Employees WHERE
(((Employees.Title)=Forms!CLECS2MainForm![QryEmployeeAssignments
subform1]!cbotitles)) ORDER BY Employees.FullName;

I have a requery event procedure on CboTitles to keep the combos
synchronized.

The problem is that it only allows me to view or add one title and employee
rather than four. I.e. it only allows me to view/add John Smith Account
Manager per customer. And not in turn add Operation Manager Bob
Jones.
Is
there a way to view/add multiple selections per customer?

Please help!
 
C

Confused

I can enter multiple records and view multiple records except when I try to
finagle the combo boxes to limit their drop downs. The problem is that I'm
trying to limit the selection of one combo box(cboemployeenames) based on the
selection of another combo box (cboTitles). I have posted this back on the
subject called Combo Box Sync that I originally posted. Al Campagna gave me
a link to a downloadable DB that has an example of what I'm trying to do. I
have posted my problem to that reply. It may make mores sense to look at
that post and to eliminate multiple posts (my fault) for the same problem
Sorry for the confusion.


tina said:
then your question isn't clear, and neither is your form setup.
The problem is that it only allows me to view or add one title and employee
rather than four.

that doesn't sound like a syncronization issue, it sounds like you can't
make multiple selections. from the context, i assumed you were trying to
select multiple items from a combobox droplist in a single record. so i
explained that you need a separate table, with multiple records, instead.
are you saying that the subform will only allow you to enter one *record*?
what happens when you try to enter a second record in the subform? more
info, please.

hth


Confused said:
Your answer has nothing to do with the question that I posted.

There are adequate tables for each relationship. There are tblCustomers,
tblEmployees, tblCustomeremplyees. Moreover all of the data is normalized.

I am asking about how to synchronize combo boxes on a subform/continuous
form.

tina said:
so one customer may be assigned to many employees, and presumably one
employee may have many customer assignments. that's a many-to-many
relationship. to model that relationship in Access you need *three* tables:
tblCustomers, tblEmployees, tblCustomerEmployees (or tblEmployeeCustomers,
same difference). tblCustomers lists all customers, tblEmployees lists all
employees, and tblCustomerEmployees lists every customer assigned to every
employee, using the primary key fields of both those tables as foreign key
fields. if CustomerA is assigned to 4 employees, there will be 4 CustomerA
records in tblCustomerEmployees - one for each assigned employee. if
Employee12 has 17 customer assignments, there will be 17 Employee12 records
in tblCustomerEmployees - one for each assigned customer.

recommend you read up/more on relational design principles, so you'll
understand how to build correct tables/relationships. for more information,
see http://home.att.net/~california.db/tips.html#aTip1.

hth



I'm trying to synchronize CboEmployeeName with CboTitles (these are bound
combo boxes) on a subform, which is a continuous form that has Customer
Names and to whom they are assigned. I.e:

Customer A Account Manager John Smith
Operation Manager Bob Jones
Order Mangager Sally Sue
Test Manager Sandy Shores
etc.

I have this statement on the row source of CboEmployeeNames

SELECT DISTINCT Employees.EmployeeID, Employees.FullName, Employees.Title
FROM Employees WHERE
(((Employees.Title)=Forms!CLECS2MainForm![QryEmployeeAssignments
subform1]!cbotitles)) ORDER BY Employees.FullName;

I have a requery event procedure on CboTitles to keep the combos
synchronized.

The problem is that it only allows me to view or add one title and
employee
rather than four. I.e. it only allows me to view/add John Smith Account
Manager per customer. And not in turn add Operation Manager Bob Jones.
Is
there a way to view/add multiple selections per customer?

Please help!
 
C

Confused

Is the reason this doesn't work the way it is, because the combos are in a
subform ( I changed the subform to Single form with the same results)? Or
because they are bound?

I thought there might be a way to make it work similar to the subquery you
gave me in the post "Search Database to Reference Subform"? Moreover where
you mention "This will cause the form to be progressively restricted on the
basis of the selections as each is made in the unbound controls.

I wondered if something like the below would work? It asks for the
parameter values when I try it. But I thought if I could get the statement
written correctly.... Or am I expending a futile effort? Just wonder why a
subquery can filter all of the records in bound combo boxes but not restrict
a combo's selection based on a subquery?

Private Sub CBOTitles_AfterUpdate()
Me.CBOEmployeeName.RowSource = "Select cboEmployeeName From" & _
" employees Where Title = " & _
Me.CBOTitles & _
" Order by fullname"
Me.CBOEmployeeName.Requery


End Sub

KenSheridan via AccessMonster.com said:
You'd have to use a 'hybrid' control for EmployeeID. Once you restrict its
RowSource on the Title column for one row in the subform all other instances
if the control in other rows will be similarly restricted. This will only
work when the combo box is bound to a natural key, but not to a surrogate key
column.

See the following for an example of how this can be done in a slightly
different context:

http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=23626&webtag=ws-msdevapps


Ken Sheridan
Stafford, England
I'm trying to synchronize CboEmployeeName with CboTitles (these are bound
combo boxes) on a subform, which is a continuous form that has Customer
Names and to whom they are assigned. I.e:

Customer A Account Manager John Smith
Operation Manager Bob Jones
Order Mangager Sally Sue
Test Manager Sandy Shores
etc.

I have this statement on the row source of CboEmployeeNames

SELECT DISTINCT Employees.EmployeeID, Employees.FullName, Employees.Title
FROM Employees WHERE
(((Employees.Title)=Forms!CLECS2MainForm![QryEmployeeAssignments
subform1]!cbotitles)) ORDER BY Employees.FullName;

I have a requery event procedure on CboTitles to keep the combos
synchronized.

The problem is that it only allows me to view or add one title and employee
rather than four. I.e. it only allows me to view/add John Smith Account
Manager per customer. And not in turn add Operation Manager Bob Jones. Is
there a way to view/add multiple selections per customer?

Please help!
 
C

Confused

Incidentally, I was able to make it work using the natural key, but it is
messing up the rest of the functionality as you described.

I've got your ComboDemo2K DB downloaded, and I prefer to use the one you
don't reccomend- frmLocations_Cont_MCB. As you know I'm sort of new to this
and had a couple questions.

I'm trying to correlate your DB to mine and in comparison I have
tblEmployeeAssigments and Employees table, whereas you have three or four
tables.

Would my cboTitles be unbound? And the CboEmployees be bound?

For the text boxes,how do I write the Control Source property such as
=GetCountyName([cboParish],cboCounty.Column(1))?

I see it working on your DB and I separated the superimposed text boxes and
combo boxes. It's hard for me to see "how" it's working. Because in each
box the same values return i.e. Cheshire in the combo box, Cheshire in the
text box etc. Well...that makes sense sort of, but what is making it limit
the selection in the second combo box (district)? In other words how do I
mimic this for CboTitles and CboEmployees?

KenSheridan via AccessMonster.com said:
No, its nothing to do with it being a subform, its because (a) the form is in
continuous form view and (b) the employee combo box's bound column is the
hidden surrogate key column EmployeeID. You can't get around it by making
the name the BoundColumn as names can be duplicated. The example you cite
from the other thread is very different; in that you were restricting the
underlying recordset of the form, in this it’s the recordset which feeds the
combo box's list which is being restricted. In the other case all the rows
were restricted by the same criteria, in this case the criteria applied to
the combo box's RowSource differ one row from another.

The reason it behaves in this way is because when the combo box is requeried
to restrict its RowSource to those employees with the selected title, any
instances of the combo box in other rows where the employee has a different
title will not have the corresponding EmployeeID value in the bound column.
The value of the control will still be the correct EmployeeID, but as that
value does not exist in the hidden first column of the RowSource there is no
corresponding value in the visible second column to be displayed in those
rows. This does not matter in single form view of course, as only one record
is seen at a time, but in continuous form view other approaches have to be
used.

When a 'natural' key is used this problem does not arise as the value of the
bound column is the value of the control, so it can be displayed even though
the combo box's RowSource is restricted to exclude that value.

When a surrogate key is the only choice, as with personal names or other
attributes whose values can legitimately be duplicated, then the only way to
achieve the correlation of the combo boxes is to use a hybrid control by
superimposing an unbound text box over a bound combo box so that it appears
as a single combo box control to the user. The alternative, and one which I
generally prefer, is to use a multi-columned bound combo box and an unbound
control which references its third column (Column(2) as the property is zero-
based). This is one of the approaches illustrated in my demo, to which I
gave you the link. One other point which that approach brings out clearly is
that only the EmployeeID should be stored in a column in the subform's
underlying table, not the Title, which should be shown in an unbound computed
control, as are the District and County values in my demo. As employeeID
determines title, to store the latter would introduce redundancy and the
table would not be normalized to Third Normal Form.

Ken Sheridan
Stafford, England
Is the reason this doesn't work the way it is, because the combos are in a
subform ( I changed the subform to Single form with the same results)? Or
because they are bound?

I thought there might be a way to make it work similar to the subquery you
gave me in the post "Search Database to Reference Subform"? Moreover where
you mention "This will cause the form to be progressively restricted on the
basis of the selections as each is made in the unbound controls.

I wondered if something like the below would work? It asks for the
parameter values when I try it. But I thought if I could get the statement
written correctly.... Or am I expending a futile effort? Just wonder why a
subquery can filter all of the records in bound combo boxes but not restrict
a combo's selection based on a subquery?

Private Sub CBOTitles_AfterUpdate()
Me.CBOEmployeeName.RowSource = "Select cboEmployeeName From" & _
" employees Where Title = " & _
Me.CBOTitles & _
" Order by fullname"
Me.CBOEmployeeName.Requery


End Sub
You'd have to use a 'hybrid' control for EmployeeID. Once you restrict its
RowSource on the Title column for one row in the subform all other instances
[quoted text clipped - 36 lines]
Please help!
 
C

Confused

It worked! Thank you! I'm daring to update the regions and states in the
same fashion, which I made into a CLECs/Region/States which is a main
form/subform/subform design.

On another design note I have a design problem similar to what you helped
with a while back on "Update Records in Current Table and Another Table" that
I really needed some advice on if at all possible, which is the following:

CLECS2<Contacts(joined on CLECID-auto number) CLECS2<TProject (joined on
CLECID) Contacts<TProject (Tried joining TProject on ContactID-auto number
also)


I have a new table called TProject. This had existing system data of
customers. I assigned each customer the appropriate CLECID which matches the
CLECS Table. I then gave it a ContactID field to coincide with the Contacts
Table, which has ContactsID.

I tried to simply join TProject with Contacts( There are yet to be any
Contacts for these customers, so I joined them to show all of the records on
Tproject and only ones that match on Contacts-outerjoin I think).

I built a form including the fields in TProject with name, email, telephone
from Contacts. It will not let me update/add any contact information in
these fields. I assume this is because it's looking for the auto number
ContactID. I've joined CLECS Contacts and TProject together many different
ways.

Is there not a way to join these together and be able to type the contact
info? I thought about joining CLECS and TProject and then doing a subform
of Contacts. But I really wanted a continuous tabular form and found that I
could not insert a subform on this type form. Or is this the only way to
accomplish?

KenSheridan via AccessMonster.com said:
Just noticed I didn't update some of the comment lines to the new names.
You can simplify and amend my demo form so it has only the two correlated
combo boxes:

1. An unbound cboTitles with a RowSource property of:

SELECT Title
FROM Titles
ORDER BY Title;

and an AfterUpdate event procedure of:

Private Sub cboTitles_AfterUpdate()

' requery employees combo box to
' show employees with selected title
Me!cboEmployees.Requery
' clear employees combo box
Me!cboEmployees = Null

End Sub

2. A bound cboEmployees combo box with a ControlSource property of EmployeeID
and a RowSource property of:

SELECT EmployeeID, Employee
FROM Employees
WHERE Title =Form!cboTitles
ORDER BY Employees.Employee;

3. An unbound text box txtTitle superimposed of cboTitles, with a
ControlSource property of:

=GetTitle([cboEmployees])

4. An unbound text box txtEmployee superimposed of cboEmployees , with a
ControlSource property of:

=GetEmployee([cboEmployees])

Along with the other code the form's module in total would thus be:

''''module starts''''
Option Compare Database
Option Explicit

' Declare array variable for storing values of unbound controls
Dim aOldVals(0)

Private Function GetTitle(varEmployeeID)

' get DistrictID for current value of ParishID field
If Not IsNull(varEmployeeID) Then
GetTitle = DLookup("Title", "Employees", "EmployeeID = " &
varEmployeeID)
Else
GetTitle = Me.cboTitles
End If

End Function

Private Function GetEmployee(varEmployeeID)

If Not IsNull(varEmployeeID) Then
GetEmployee = DLookup("Employee", "Employees", "EmployeeID = " &
varEmployeeID)
End If

End Function

Private Sub cboTitles_AfterUpdate()

' requery employees combo box to
' show employees with selected title
Me!cboEmployees.Requery
' clear Parish combo box
Me!cboEmployees = Null

End Sub

Private Sub cmdClose_Click()

DoCmd.Close acForm, Me.Name

End Sub

Private Sub cmdUndo_Click()

' force form to Dirty by updating ParishID to itself
Me!cboEmployees = Me!cboEmployees
Me.Undo

End Sub

Private Sub Form_Close()

On Error Resume Next
Forms!frmOpen.Visible = True

End Sub

Private Sub Form_Current()

If Me.NewRecord Then
Me!cboTitles = Null
Else
Me!cboTitles = GetTitle(Me!cboEmployees)
End If

Me!cboTitles.Requery
Me!cboEmployees.Requery

aOldVals(0) = Me!cboTitles

End Sub

Private Sub Form_Undo(Cancel As Integer)

If Not Me.NewRecord Then
Me!cboTitles = aOldVals(0)
End If

Me!cboTitles.Requery
Me!cboEmployees.Requery

End Sub
''''module ends''''

Watch out for any lines which your newsreader might have split over two lines
in the above.

Basically the way it works is that when you move focus to one of the combo
boxes by clicking on its arrow its text box part becomes visible and its list
drops down. When you move focus off the control the superimposed text box
becomes visible. The functions get the text values for these by looking them
up from the relevant table on the basis of the corresponding key value which
is the hidden value of the bound cboEmployees combo box. In the case of the
GetTitle function, when inserting or editing a record the cboEmployees combo
box will be Null until an employee has been selected after selecting a title,
so in this case the function assigns the value of the unbound cboTitles combo
box to the text box until an employee is selected.

The Undo button, which works by storing the value of the unbound cboTitles
control in an array isn't really necessary here of course as only the one
control is involved, but I've left in it nevertheless to illustrate how it
would work with a more complex scenario with a hierarchy of more levels.

Hopefully, with the above you'll be able to get it to work, but if not mail
me at:

kenwsheridan<at>yahoo<dot>co<dot>uk

and I'll send you the simplified file from which the above code is taken.

Ken Sheridan
Stafford, England
Incidentally, I was able to make it work using the natural key, but it is
messing up the rest of the functionality as you described.
[quoted text clipped - 24 lines]
Please help!
 
C

Confused

This thing is like a golf swing. You fix one thing and have a whole array of
new problems... Yes, this did the trick. I thought an easy way would be to
query CLECS2 and Contacts, showing all records on CLECS2 and then just doing
an update query and inserting something miniscule in one of the fields (
didn't do it this way but thought if there was a bigger project that might be
the route to go. Or even inserting something in a field of Contacts that is
not even viewable on the form)? That way there would be a contactID for all
the customers. I then did an update query inserting Contact ID in the
TPoject fields.

But then when I add your putative TblEmployeeAssignments to assign the
customer, I then ran into the same problem as far as it not being updateable.
I tried joining this table on CLECID, given every table in the query grid
has this field

CLECS2---<Contacts---<TProject < TblEmployeeAssignments < Employees

But to fix the problem I added EmployeeID to TProject and did an update
query inserting employeeid into Tproject. It all works now. I hope I did
all of this right?

I haven't got to the combo boxes yet, because right now I'm just sticking
with one contact per customer on this project. But did you mean that I could
insert multiple contacts per customer or still just the one contact per
customer?

Anyway on tblEmployeeAssignments I had a question if you had the chance. I
was wondering about adding the managers to the group that is already in there
i.e.
Mary, Sally, Sue all are managed by Rocky. Jane, Joe, Ellen are managed
by Glenn. So like in a combo box if Rocky selected his name how would he see
all of his customers? Or does he need his own employeeID in
TblEmployeeAssignments? I just thought tblEmployeeAssignments is going to be
gargantuous if there are more assignments.

Indebted always...Regards.


KenSheridan via AccessMonster.com said:
As far as I can see this is a classic 'missing link' problem. I think I've
given you the following 'regions' example before, but even so I'll reiterate
it for clarity here:

Its commonly encountered in international databases of geographical data (I
came upon it a while ago in an OECD database for instance) where you have a
table Cities referencing a table Regions referencing a table Countries. Not
all countries have a regional structure, however, so the solution is to have
a row in Regions for each country with a Region value of N/A. It follows
from this that the key of Regions must be a surrogate RegionID of course.

In your case Contacts is analogous to Regions as you say "there are yet to be
any Contacts for these customers", so in Contacts you'd first need a row for
each CLEC with a value of N/A. You can then insert the relevant ContactID
and CLECID values into each row in TProject to reference the relevant N/A
row in Contacts for the CLEC. in question. Once you’ve done this for all
existing TProject rows you can enforce its relationship with Contacts. As
ContactID is the key of Contacts you don't need a CLECID column in TProject
in fact, nor the relationship from TProject to CLECS2.

So the query would now be a simple one of CLECS2 inner joined to Contacts on
CLECCID, Contacts inner joined to TProject on ContactID. CLECS2 does not
need to be joined to TProject as each row in the former maps to rows in the
latter via Contacts.

The relationships mirror the joins in the query:

CLECS2---<Contacts---<TProject

A form based on this query will be updatable, but you should make any
controls bound to columns from Contacts or CLECS2 read only by setting their
Locked property to True (Yes) and their Enabled property to False (No); this
prevents values from the referenced tables being edited, allowing only those
from TProject to be edited. Changing a 'N/A' contact to an existing 'real'
contact simply requires editing the ContactID in TProject, which you'd do via
a bound combo box on the form. To add a new contact for a customer, however,
means first inserting a new row in Contacts and a value in that row for the
CLECID of that contact in this instance. You can do this via the combo box's
NotInList event procedure. Just how you do this depends on how you are
storing the contact names in contacts, whether (a) as a single Contact column.
e.g. Ken Sheridan, or (b) as FirstName and LastName columns, Ken in the
former Sheridan in the latter. If (a) then the code would be like this:

Dim ctrl As Control
Dim strMessage As String

Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"

If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
DoCmd.OpenForm "frmContacts", _
DataMode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=NewData
' ensure frmContacts closed
DoCmd.Close acForm, "frmContacts"
' ensure contact has been added
If Not IsNull(DLookup("ContactID", "Contacts", "Contact = """ & _
NewData & """")) Then
Response = acDataErrAdded
Else
strMessage = NewData & " was not added to Contacts table."
MsgBox strMessage, vbInformation, "Warning"
Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If

This opens frmContacts, which is a form bound to the Contacts table, in add
mode so that a CLEC can then be selected for the contact. In this form's
Open event procedure you'd put:

If Not IsNull(Me.OpenArgs) Then
Me.Contact.DefaultValue = """" & Me.OpenArgs & """"
End If


If (b), which is the preferred way of storing names of course, the combo box
would be set up like this:

ControlSource: ContactID

RowSource: SELECT ContactID, FirstName & " " & LastName FROM Contacts
ORDER BY LastName, FirstName;

BoundColum: 1
ColumnCount: 2
ColumnWidths: 0cm;8cm

If your units of measurement are imperial rather than metric Access will
automatically convert the last one. The important thing is that the first
dimension is zero to hide the first column and that the second is at least as
wide as the combo box.

So to insert a row into Contacts you have to parse the value entered into
separate first and last names. Here's an example of the NotInList event
procedure for a combo box of SalesPersons in one of my files set up in this
way:

Const conMESSAGE = "Salesperson's name must be entered " & _
"in format 'FirstName <space> LastName'"

Dim args As String
Dim strFirstName As String
Dim strLastName As String
Dim intSpacePos As Integer
Dim ctrl As Control
Dim strMessage As String

Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"

intSpacePos = InStr(NewData, " ")

If intSpacePos = 0 Then
MsgBox conMESSAGE, vbExclamation, "Invalid Operation"
Response = acDataErrContinue
Else
strFirstName = Left(NewData, intSpacePos - 1)
strLastName = Mid(NewData, intSpacePos + 1)

' add named arguments
AddArg args, "argFirstName", strFirstName
AddArg args, "argLastName", strLastName


If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
DoCmd.OpenForm "frmSalesPersons", _
DataMode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=args
' ensure frmSalesPersons closed
DoCmd.Close acForm, "frmSalesPersons"
' ensure salesperson has been added
If Not IsNull(DLookup("SalesPersonID", "SalesPersons", _
"FirstName = """ & strFirstName & """ And " & _
"LastName = """ & strLastName & """")) Then
Response = acDataErrAdded
Else
strMessage = NewData & " was not added to Salespersons table.
"
MsgBox strMessage, vbInformation, "Warning"
Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If
End If

The code for the Open event of the frmSalesPersons form in this case is:

Dim args As String

If Not IsNull(Me.OpenArgs) Then
args = Me.OpenArgs
' get named named arguments
Me.FirstName.DefaultValue = """" & Arg(args, "argFirstName") & """"
Me.LastName.DefaultValue = """" & Arg(args, "argLastName") & """"
End If

One caveat: the above does not allow for a first name with a space in it, e.g.
'Mary Lou'. Names such as 'Victoria de los Angeles' would treat 'de los
Angeles' as the last name.

You'll see that the code in the above two event procedures calls AddArg and
Args functions, so you'd also need to add the following module, which allows
various ways of passing multiple arguments between forms or reports, to your
database:

Private Const OFFSET As Long = 127
Private Const ASSIGNOP As String = "=="

Function Arg(buffer, idx) As Variant

If IsNumeric(idx) Then
I& = InStr(1, buffer, Chr(idx + OFFSET - 1))
token$ = Chr(idx + OFFSET)
I& = InStr(I&, buffer, ASSIGNOP) + 2
Else
I& = InStr(1, buffer, idx) + Len(idx) + 2
token$ = Chr(Asc(Mid(buffer, InStr(1, buffer, idx) - 1, 1)) + 1)
End If
Arg = Mid(buffer, I&, InStr(I&, buffer, token$) - I&)

End Function

Function Argname(buffer, idx) As String

I& = InStr(1, buffer, Chr(idx + OFFSET - 1))
token$ = Chr(idx + OFFSET)
Argname = Mid(buffer, I& + 1, InStr(I&, buffer, ASSIGNOP) - (I& + 1))

End Function

Function ArgCount(buffer) As Long

ArgCount = Asc(Right(Chr(OFFSET) & buffer, 1)) - OFFSET

End Function

Sub AddArg(buffer, Argname, argval)

If Len(buffer & "") = 0 Then buffer = Chr(OFFSET)
If IsNumeric(Argname) Then Argname = ArgCount(buffer) + 1
buffer = buffer & Argname & ASSIGNOP & argval & Chr(Asc(Right(buffer, 1))
+ 1)

End Sub

Sub AddArgList(buffer, ParamArray Tokens())

For I& = 0 To UBound(Tokens)
AddArg buffer, I& + 1, Tokens(I&)
Next

End Sub

For a demo of how this module works see:

http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=24091&webtag=ws-msdevapps


Ken Sheridan
Stafford, England
It worked! Thank you! I'm daring to update the regions and states in the
same fashion, which I made into a CLECs/Region/States which is a main
form/subform/subform design.

On another design note I have a design problem similar to what you helped
with a while back on "Update Records in Current Table and Another Table" that
I really needed some advice on if at all possible, which is the following:

CLECS2<Contacts(joined on CLECID-auto number) CLECS2<TProject (joined on
CLECID) Contacts<TProject (Tried joining TProject on ContactID-auto number
also)

I have a new table called TProject. This had existing system data of
customers. I assigned each customer the appropriate CLECID which matches the
CLECS Table. I then gave it a ContactID field to coincide with the Contacts
Table, which has ContactsID.

I tried to simply join TProject with Contacts( There are yet to be any
Contacts for these customers, so I joined them to show all of the records on
Tproject and only ones that match on Contacts-outerjoin I think).

I built a form including the fields in TProject with name, email, telephone
from Contacts. It will not let me update/add any contact information in
these fields. I assume this is because it's looking for the auto number
ContactID. I've joined CLECS Contacts and TProject together many different
ways.

Is there not a way to join these together and be able to type the contact
info? I thought about joining CLECS and TProject and then doing a subform
of Contacts. But I really wanted a continuous tabular form and found that I
could not insert a subform on this type form. Or is this the only way to
accomplish?
Just noticed I didn't update some of the comment lines to the new names.
[quoted text clipped - 159 lines]
Please help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top