(Noob) Foriegn keys?

Rick Stanich

King and Supreme Ruler
Local time
Today, 04:00
Joined
May 13, 2009
Messages
93
The snippet of code below should add a new line to the table "tblPartRev" but it doesnt. I think it has to do with a foriegn key in that table.

The table: tblPartRev
pkPartRevID
fkPartID
txtRev

Code:
                    myrecset1.Open "tblPartRev", , adOpenDynamic, adLockOptimistic
                    With myrecset1
                        .AddNew
                        'add foriegn key here?
                        !txtRev = myrev
                        .Update
                        .Close
                    End With
                    Set myrecset1 = Nothing

I have tried to find examples using foriegn keys but have been unsuccesfull.

I am able to add new to another table:
Code:
                    myrecset1.Open "tblParts", , adOpenDynamic, adLockOptimistic
                    With myrecset1
                        .AddNew
                        !txtPartNo = mypart
                        holdPartIDpk = !pkPartID
                        .Update
                        .Close
                    End With
                    Set myrecset1 = Nothing
Allthough it doesnt have a foriegn key.

Any hints, tips or examples are appreciated.
 
What is your PK? Is that an Autonumber?
Do you have any fields in the table that are "required" or are set to " not allow null values" ???
 
PK is autonumber
fk is Number (Long integer)
txt is text

For null values, if you mean "not allow zero values", tblPartRev is set to "Yes"
Required is set to "No"
 

Attachments

  • GM Relationships.jpg
    GM Relationships.jpg
    61.5 KB · Views: 132
How about the properties of your fkPartID? Looks like it might be set to "Required" yes or "Allow Zero Length" no
 
tblPartRev:
fkPartID;
Required = No
doesnt have an option for "Zero length"?

txtRev;
Zero length = Yes
 
Solved:
Learned to establish foriegn key links in code
Example:
Code:
                    With myrecset3
                        .AddNew
                        !txtRev = myrev
                        [COLOR=red]!fkPartID = holdpartpk [/COLOR][COLOR=lime]'Foriegn Key link[/COLOR]
                        holdpartrevpk = !pkPartRevID
                        .Update
                        .Close
                    End With
 

Users who are viewing this thread

Back
Top Bottom