Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking tables 1

Status
Not open for further replies.

assiri

Technical User
Aug 17, 2008
17
0
0
GB
hi,
This may be a very basic question,but please help me..

I have two tables tablel01 and tabel02,which have one-to-Many relationship(table01 is "one" side)
table01 table02
field1-Autonum field1-Autonum
field2-Text field2-Number(forign)
field3-Text field3-Text


I have related these tables,field size properties of the relating field are set to "long integer"

I have added data to the table01 using,
set rs=db.Openrecordset"table01"
rs.AddNew
rs("field2").Value=Variable1
rs("field3").Value=Variable2
rs.update
Its OK..
but when I am adding data to the table02 using,

set rs=db.Openrecordset"table02"
rs.AddNew
rs("field2").Value=Variable1
rs("field3").Value=Variable3
rs.update
Error occurs "data type mismatch".I have understood that table02 foreign key has number data type and I have assigned a text fied.please tell me how to enter data to the table02's foreign key?????

 
Table02.field02 must = Table01.field01 if it's the FK fella

JB
 
Hi,

Thankx JB,
I have the Table 01, Field2 values and field 3 values in my program(these values come to seperate variables variable1 and variable2)from user input.
Please tell me how to get the primary key value relavant to Table1, field2 inorder to build the relationship with Table02
(in other words variable1 s' primary key)
If u could state the code line it would be great,because this is my first time building a relationship manually.
Thankx
assi
 
Using your example:

Code:
[red]dim intPK as long[/red]
 
set rs=db.Openrecordset"table01"
rs.AddNew
rs("field2").Value=Variable1
rs("field3").Value=Variable2
[red]intPK=rs("field1")[/red]
rs.update
Its OK..
but when I am adding data to the table02 using,

set rs=db.Openrecordset"table02"
rs.AddNew
rs("field2").Value=[red]intPK[/red]
rs("field3").Value=Variable3
rs.update

JB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top