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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

primary key using 2 fields question 1

Status
Not open for further replies.

Gerilee

Programmer
Mar 23, 2001
47
US
I have a primary key in a table comprised of 2 fields. Fld1 by itself can be a duplicate and Fld2 by itself can be a duplicate but together they must be unique. Fld1 must have a value entered but Fld2 does not always need a value entered. Is this possible? I can't seem to get it to work. I just keep getting the error message that you can't enter nulls in a primary key field. I thought that since both fields made up the primary key that as long as there was a value in Fld1, this would be okay.

Thanks for any help!
 
You may try to don't allow Null but ZeroLength for Fld2

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thanks for the quick response. It works like a charm.
 
I wanted to clarify what I had to do to make this solution work. Along with setting Required = No and Allow Zero Length = Yes in the table, I also had to put the following code in the After Update property of Fld2 --

If IsNull(Me.Fld2) Then
Me.Fld2 = " "
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top