473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How do I create a record from two different tables on the same form?

Hi Everyone,
I have a form (Access 2000) with text and combo boxes bound to a table showing information about our contracts.

There is also a list box in this form querying client names from another table.

My goal is to have a record of a contract showing, then to highlight a client from the queried list box so i can ultimately click a button and add the contract number and the client name to a table which stores only that information (contract number & clientID).

I have created tables called: Contracts, Clients, ClientContractJunction. The last table has a many to many relationship with the Clients and Contracts tables (as there will be contracts with many clients and clients attached to many contracts)

Can anyone offer a direction in which to take this problem? I'm assuming I need a command button with some code to add the selected information to a record in the ClientContractJunction table. Unfortunately the code is above my skill level - but I'm determined to learn how to do it :-).
Jul 30 '08 #1
7 1414
NeoPa
32,556 Expert Mod 16PB
If you had a Contract maintenance form you could add an unbound ComboBox populated by the [Clients] table. The trigger for the code to create a record matching the link in your [ClientContractJunction] table would be a Command button.

Depending on your preference, you could add the record using VBA & recordsets, or you could knock up some SQL to execute.
Aug 5 '08 #2
Thanks NeoPa,
I created an append query which will run when a command button on the form CONTRACTS is clicked. Unfortunately it gives me a message that "i'm about to append 0 rows". Here is the SQL statement. If anyone has any ideas please let me know. I put in the WHERE statement but i'm not sure if that's right.
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO clientContractJunction
  2.            ([Contract Number],
  3.             ClientID)
  4.  
  5. SELECT [Contracts].[Contract Number],
  6.        [Clients].[ClientID]
  7.  
  8. FROM  Clients INNER JOIN
  9.      (Contracts INNER JOIN clientContractJunction
  10.   ON ([Contracts].[ClientID]=[clientContractJunction].[ClientID])
  11.  AND ([Contracts].[Contract Number]=[clientContractJunction].[Contract Number]))
  12.   ON ([Contracts].[ClientID]=[Clients].[ClientID])
  13.  AND ([Clients].[ClientID]=[clientContractJunction].[ClientID])
  14.  
  15. WHERE (([Contracts].[Contract Number]=[Forms]![Contracts]![Contract Number])
  16.   AND  ([Clients].[ClientID]=[Forms]![Contracts]![lstSource]));
Aug 14 '08 #3
NeoPa
32,556 Expert Mod 16PB
Is the SQL coded into a QueryDef or do you execute it from a string in your code?

I would focus primarily on what values are in your [Contract Number] and [lstSource] controls at the time the button is clicked. Particularly if you may be using Nulls (no data entered).
Aug 14 '08 #4
agreed... my goal is for this query to run from a command button on the form.

The contract number field on this form displays the number for a given record and the lstSource list box does display the query of all the Clients' names. In order to attach client names with a contract i thought i would be fairly straightforward to click on a name in the lstSource and add the client name and the contract number in that field to a third table (called ClientContractJunction) when the command button was clicked to run the append query. Judging by the fact that it says '0 rows will be appended' it seems that Access is not seeing the the record of the contract number displayed or the client name or both. I'm obviously missing a key part but I'm not sure what it is. Thanks for your help so far!

here is another SQL code slightly more cleaned up (I hope):
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO clientContractJunction ( [Contract Number], ClientID )
  2. SELECT Contracts.[Contract Number], Clients.ClientID
  3. FROM Clients INNER JOIN Contracts ON Clients.ClientID = Contracts.ClientID
  4. WHERE (((Contracts.[Contract Number])=[Forms]![Contracts]![Contract Number]) AND ((Clients.ClientID)=[forms]![Contracts]![lstSource]));
Aug 14 '08 #5
NeoPa
32,556 Expert Mod 16PB
The SQL you've got seems fine to me.

The debugging of this is going to be mainly hands on I'm afraid as it is all about the actual data used (which I don't have and would find difficult to comprehend in isolation even if some were posted).

What I can do (possibly the last of any help) is to suggest that in your VBA code you can display the two controls at the time you are about to execute the SQL. Something like :
Expand|Select|Wrap|Line Numbers
  1. strMsg = "[Forms]![Contracts]![Contract Number] = '%N'" & VbCrLf & _
  2.          "[Forms]![Contracts]![lstSource] = '%S'"
  3. strMsg = Replace(strMsg, "%N", [Forms]![Contracts]![Contract Number])
  4. strMsg = Replace(strMsg, "%S", [Forms]![Contracts]![lstSource])
  5. Call MsgBox(strMsg)
  6. 'Execute your SQL here
Just seeing what's displayed is often enough to ring bells.

I hope this sorts things out for you.
Aug 15 '08 #6
through some trial and error I managed to figure out that the inner join was the problem. Once I got rid of that link. It worked just fine. here's the querry. Thanks a huge amount for your help!

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO clientContractJunction ( [Contract Number], ClientID )
  2. SELECT Contracts.[Contract Number], Clients.ClientID
  3. FROM Clients, Contracts
  4. WHERE (((Contracts.[Contract Number])=[Forms]![Contracts]![Contract Number]) AND ((Clients.ClientID)=[forms]![Contracts]![lstSource]));
  5.  
Aug 27 '08 #7
NeoPa
32,556 Expert Mod 16PB
I'm just sorry I couldn't help more, but very pleased you were able to resolve your problem yourself, even without much help.

Welcome to Bytes!
Aug 28 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: David Elliott | last post by:
I can create this: ?xml version="1.0" standalone="yes" ?> <ConfigOpt> <record> <Field_1>Text # 1</Field_1> <Field_2>Text # 2</Field_2> </record> </ConfigOpt>
6
by: skgolden | last post by:
My husband and I own a small temporary labor company and deal with 4 major clients (A,B,C & D), each of which has about 2 dozen units in our tristate area that we deal with (ie, Company A, units...
24
by: flkeyman | last post by:
Work in legal office. Trying to create solid designed database structure. This is list of tables w/fields and primary keys. Any comments/advice greatly appreciated. tbl-Defendants CaseNumber...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
25
by: tekctrl | last post by:
Anyone: I have a simple MSAccess DB which was created from an old ASCII flatfile. It works fine except for something that just started happening. I'll enter info in a record, save the record,...
12
by: tekctrl | last post by:
Environment; Win2K PC with 1Gb of RAM and plenty of HD space running Access 2002 Issue; Access presents a blank data entry form in the Forms view when the New Record icon is used. However, it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.