Populate txtbox From Database
I have a database with several products and information per each product; price, oz etc. I have a form with a dropdown and then a textbox for the price, oz, etc. I'd like it so that the user can add new products by typing into the dropdown and then the successive fields. And that the user can select a product from the dropdown and the fields are populated with the data from the database and the user can then change the data. I have one save button for the add and update. My form is unbound and my textboxes are bound. The txtboxes now say #Name? and I cannot change them and they are not populating. The following is my code:
Dim conn As New ADODB.Connection
Option Compare Database
Private Sub cbItem_AfterUpdate()
Dim rs As New ADODB.Recordset
Set conn = Nothing
Set conn = CurrentProject.Connection
conn.BeginTrans
DoCmd.GoToRecord , , acNewRec
'On Error GoTo newItem
sql = "Select * from tblItems where Item = """ & cbItem.Value & """"
rs.Open sql, conn, adOpenStatic
Set rs = Me.Recordset
Exit Sub
newItem:
DoCmd.GoToRecord , , acNewRec
txtItem = cbItem.Value
End Sub
Private Sub cmdEnter_Click()
On Error GoTo Err_cmdEnter_Click
conn.CommitTrans
Exit_cmdEnter_Click:
Exit Sub
Err_cmdEnter_Click:
MsgBox Err.Description
Resume Exit_cmdEnter_Click
End Sub
Private Sub cmdEnter_Enter()
End Sub
Private Sub Form_Load()
End Sub
Thanks,
Awieds
|