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 April 15th, 2005, 05:55 AM
Gus Gus is offline
Registered User
 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Coding help with data from a query

Hi guys,

Hope someone can help. It's been a little while since I programmed anything in VBA. Right now I have a DB project for anit-violence organisation that is presenting small problem to me. Here's my terribly short and messy pseudo code:

When cboClientName changes
   get the data from the field in the fourth column
   assign that data to txtClientID
end

Here's a break down. I have a query that gets a complete list of clients and their ID number. After I have choosen the name from the combo box, I want the ClientID vlaue to be shown in the text box txtClientID.

The query looks up First Name, Middle Name, Last Name, Client ID.

Thanks for any help,

Gus
 
Old April 15th, 2005, 06:16 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

What you want to accomplish can be done like this...

Me.txtClientID = Me.cboClientName.Column(3)

The index for Column starts at zero. To get the fourth column, use three.

However, I would highly recommend you do this...

Change the order of your query to put ClientID first.

In the properties of cboClientName:
Set the Bound Column to 1.
Set the Column Count to 4.
Set Column widths to 0";1";.5";1"
Set List Width to 2.75" (always set List Width to total of Columns widths plus 0.25" to allow for scroll bar)

Throw away the txtClientID field and just use cboClientName as the field that has the ID. You might want to rename cboClientName to cboClientID to keep things clear.

QED. No coding required.

This assumes that you don't really need the First Name of the client in cboClientName and that you don't need to show the users the ID number.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
 
Old April 15th, 2005, 06:22 AM
Gus Gus is offline
Registered User
 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that. I completely forgot about the Me thingy. Well that solves a lot of problems.

Gus
"It's the fuzz! Cheese it!" - Bender
 
Old April 15th, 2005, 06:32 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

BTW, depending on the client base, if you are changing the order of your fields, you might want to put Last Name second in your query so users can type the first few characters of the person's last name to jump to the area where the name is. Most people tend to think of these lookups by last name.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Query Snapshot of Data in % feets SQL Server 2000 4 November 8th, 2007 04:41 AM
Help with efficient coding (part of Dynamic Query miamikk SQL Language 1 July 17th, 2007 05:32 AM
Hand Coding VS Data Wizards Bulldog BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 May 22nd, 2007 04:21 AM
Query data and exporting data from one sheet to an testman Excel VBA 2 April 28th, 2005 02:40 PM
Coding for data input from one form to 2 tables... dgarcia1128 Access VBA 1 February 19th, 2004 12:35 AM





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