PDA

View Full Version : Solved: Returning primary key value instead of combo box selection



feathers212
01-15-2007, 02:13 PM
I have a form that uses an unbound combo box to choose a material to receive. The material is choosen from a master list. Each material on the master list has it's own material ID which is set up as the primary key.

The form also has unbound text boxes for the date and quantity of the receipt. When the submit receipt button is clicked, the receipt is added to the transaction table:


Private Sub Submit_Receipt_Click()
On Error GoTo Err_Submit_Receipt_Click

Dim db As Database
Dim rs As Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("Material Transactions")

With rs
.AddNew
![Material Name] = Me.ReceiptMaterial.Value
![Date] = Me.ReceiptDate.Value
![Transaction] = "Receipt"
![Quantity] = Me.ReceiptQuantity.Value
.Update
.Close
End With

DoCmd.Close acForm, "Receipts Form", acSaveYes
MsgBox ("Receipt entered into database.")

Exit_Submit_Receipt_Click:
Exit Sub

Err_Submit_Receipt_Click:
MsgBox Err.Description
Resume Exit_Submit_Receipt_Click

End Sub


Everything works just fine, except for the Material Name portion. The programming enters in the associated material ID rather than the actual name that was chosen from the drop down.

I'm not sure about the Me.ReceiptMaterial.Value. Is this correct, or should I not be using the .Value?

JimmyTheHand
01-16-2007, 01:23 AM
Hi Heather :hi:

I guess Me.ReceiptMaterial is the combobox, and a multiple column one.
If so then .Value is OK, but you should check the bound column property of the combobox. When using a multiple column combobox you can choose which column is returned by the .Value property.


Jimmy

feathers212
01-16-2007, 05:46 AM
Hmmm....thought I had that all setup correctly, but I guess not. Made the change and it works perfectly now!!

Thanks again:thumb