Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 May 3rd, 2005, 07:43 PM
Registered User
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieving items from a table - Immediate Help

I am a novice programmer and I am working on VBA code in Access and need your help.

I have a list box that contains the buyers code and buyers name. This list box should have a click event that gets all of the items in the items table when a buyer is selected from the list box.

Like I said I am a very weak programmer and need your help on the code for this problem
 
Old May 4th, 2005, 10:22 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   This is fairly easy. Do you want the button to open a form or report? Is your combo box bound to a primary key on the buyer's table? If you can send some structure, we can do this real quick.

You will want your starting form to have a combo box that looks up the buyers in the buyer's table by PK, then displays the buyers' names and code. Is the code the PK? This should be the bound column.

Then you have a button on the form that opens another form or report that displays all the info about the buyer you have selected. Assume it is a report based a either the buyer's table or a qry of the buyers table. For the button's On Click event you would add this code:

'=====
Dim intBuyerCode As Integer 'assuming its an integer
Dim stDocName As String
Dim stLink As String

intBuyerCode = Me.cboYourBuyerComboBoxName
stLink = "[BuyerPK] = " & intBuyerCode

stDocName = "rptYourBuyerReport"
DoCmd.OpenReport, stDocName, acPreview, , stLink
'=====

If it is a form, that would be different, or if the buyer code were a string, that would require this syntax:

'=====
stLink = "[BuyerPK] = " & "'" & stBuyerCode & "'"

HTH,




mmcdonal
 
Old May 4th, 2005, 02:39 PM
Registered User
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have it set up to where I am connecting to the Items table in the database. Once the connection is established, I should then click on a buyer from a list box that is shown on the form. This should then retrieve all of that buyers info from the Items table based on the Buyers Code and put it in a sub form that I have.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to update table with listview items Singh591 Pro VB.NET 2002/2003 0 December 30th, 2006 11:13 PM
Retrieving data from a table given a PK value galaxy3 VB Databases Basics 1 June 22nd, 2006 12:12 PM
retrieving multiple rows from table blackbeauty SQL Language 1 August 8th, 2005 03:55 AM
Retrieving unselected items from a select box tdaustin Classic ASP Basics 2 May 5th, 2005 02:22 AM
Having problems retrieving an array to a table! penta Access 2 September 27th, 2004 07:23 AM





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