snub said:
[blue]Should I make only ID the primary key? If so, [purple]why is it important to be designed that way?[/purple][/blue]
Its not that its important to be disigned this way, as much as the compound key is not necessary. Compound keys have their place, but not here.
Consider the PK logic for tblManufacturers. A PK here should [purple]
uniquely identify[/purple] a manufacturer . . . wether its a compound ten key, or single key PK. The [purple]Idea is, why do with many what you can do with the one![/purple] This is the over complication that arises when using compound keys. Any time you involve yourself in this type of PK, you have to take account of all the keys in the mix, particularly when assigning new keys (instead of assigning one, you'll have to assign two or more). [purple]Its a matter of making it easier on yourself![/purple]
So yes . . . I'd make ID the singular PK for table tblManufacturers. Its simple, easily unique, fits the logic of the table, and most importantly . . . gives you [blue]ease of manipulation[/blue]. Always bear in mind, PK's are what access needs to identify records.
Getting back to the problem, this is what you have when the user answers yes:
Code:
[blue] ElseIf intResult = vbYes Then
[green]'Add a new record to the look-up table[/green]
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strTable)
rst.AddNew
rst(strFieldName) = strNewData
rst.Update[/blue]
[ol][li]Your adding to the wrong table (should be [blue]tblProductName[/blue]).[/li]
[li][purple]
Note: no FK (Foreign Key) is assigned![/purple].[/li]
[li]Considering your compound key, you may have to [blue]add the key Manufacturer[/blue].[/li]
[li]Note: if the [blue]PK[/blue] of [blue]tblProductName[/blue] is not autonumber, it'll have to be appended as well![/li][/ol]
Get the picture with the missing key(s)! . . . take care of the PK/FK when you add and your problem is solved . . .
Considering you should have:
[ol][li]A one to many relationship between tblManufacturers & tblProductName.[/li]
[li] ManufacturerID is the single PK of tblManufacturers.[/li]
[li]ProductID of tblProductName is autonumber.[/li][/ol]
This is what you should have:
Code:
[blue]Private Sub cboManufacturer_NotInList(strNewData As String, _
intResponse As Integer)
Dim db As DAO.Database, rst As DAO.Recordset
Dim Msg As String, Style As Integer, Title As String, SQL As String
Msg = "Do you want to add '" & strNewData & "' " & _
"as a new Manufacturer entry?"
Style = vbYesNo + vbExclamation + vbDefaultButton1
Title = "Product Name Not In List! . . ."
If MsgBox(Msg, Style, Title) = vbYes Then
Set db = CurrentDb
Set rst = dbs.OpenRecordset("tblProductName")
Set CBx = Me!cboManufacturer
rst.AddNew
rst!Manufacturer = strNewData
rst!ManufacturerID = Me!cboManufacturer
rst.Update
intResponse = acDataErrAdded
Set rst = Nothing
Set db = Nothing
Else
intResponse = acDataErrContinue
Me!cboManufacturer.Undo
End If
End Sub[/blue]
[purple]Your thoughts . . .[/purple]
See Ya! . . . . . .