Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2004, 10:06 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old August 23rd, 2004, 10:17 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just changed it so that the form is now bound. The textboxes now populate themselves however I get the following error: Type Mismatch. The error is on the following line:
set rs=me.recordset

Thanks

 
Old October 7th, 2004, 05:23 PM
Authorized User
 
Join Date: Oct 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try changing the "Set rs = Me.Recordset" to "Set rs = Me.RecordSource"
 
Old October 20th, 2004, 03:47 PM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. I tried it and I got an error: Invalid use of property.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieve data from database and populate on PDF kotaiah Java Basics 1 February 13th, 2007 06:00 AM
Populate Select Menu from MySQL Database joviyach PHP Databases 4 June 24th, 2006 09:38 PM
populate Menus from Database harrysingh26 .NET Framework 2.0 3 March 2nd, 2006 07:54 AM
populate Menus from Database harrysingh26 ASP.NET 2.0 Professional 0 February 21st, 2006 02:39 AM
Populate a drop down from database topshed Access 5 November 29th, 2004 09:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.