Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

MS Access - put a listbox field into a variable

Thread Tools
 
Search this Thread
 
Old 25 April 2006, 10:04 PM
  #1  
spectrum48k
Scooby Regular
Thread Starter
 
spectrum48k's Avatar
 
Join Date: Feb 2006
Posts: 2,519
Likes: 0
Received 0 Likes on 0 Posts
Default MS Access - put a listbox field into a variable

I have a listbox based on a SELECT query

Each row has 4 fields

The user selects a row in the listbox.

Is there a way to put the contents of a field into a variable ?

eg. if field #3 of the selected row contains "hello", can I put that into a variable using the underlying VB ?

eg.
Dim mystring as string
mystring = forms![myform]![listbox]![field3]

Its ages since I used Access, so I'm just feeling my way again, and I'm pretty sure I've done this before.
Old 25 April 2006, 10:36 PM
  #2  
bob269
Scooby Regular
 
bob269's Avatar
 
Join Date: Mar 2003
Posts: 2,654
Likes: 0
Received 1 Like on 1 Post
Default

What are you trying to acheive?

I assume you've got some sort of flag or field/text on the form which you want to change depending on the selection?

You'd enter the expression in the "afterupdate" part of the "field3" properties and tell it xxx.value = field3.value or whatever.
Old 25 April 2006, 11:01 PM
  #3  
spectrum48k
Scooby Regular
Thread Starter
 
spectrum48k's Avatar
 
Join Date: Feb 2006
Posts: 2,519
Likes: 0
Received 0 Likes on 0 Posts
Default

imagine the listbox contains name, addr1, add2, tel in its fields

I want to do this:

1. click on a row in the list box
2. open a form
3. fill in the name box with contents of the name field, from the listbox
4. fill in the addr1 box with contents of the addr1 field, from the listbox
etc...

I know you can do it - just can't remember, and google can't seem to help me.
Old 25 April 2006, 11:05 PM
  #4  
bob269
Scooby Regular
 
bob269's Avatar
 
Join Date: Mar 2003
Posts: 2,654
Likes: 0
Received 1 Like on 1 Post
Default

If you want to store a variable between forms you need to create a global module
Old 25 April 2006, 11:11 PM
  #5  
spectrum48k
Scooby Regular
Thread Starter
 
spectrum48k's Avatar
 
Join Date: Feb 2006
Posts: 2,519
Likes: 0
Received 0 Likes on 0 Posts
Default

bob, are you sure ? I'm pretty sure I can reference something on the underlying form without declaring a global.

isn't it something like:

forms![myform]![listbox].field1

or something like that ?
Old 25 April 2006, 11:15 PM
  #6  
bob269
Scooby Regular
 
bob269's Avatar
 
Join Date: Mar 2003
Posts: 2,654
Likes: 0
Received 1 Like on 1 Post
Default

Originally Posted by spectrum48k
bob, are you sure ? I'm pretty sure I can reference something on the underlying form without declaring a global.

isn't it something like:

forms![myform]![listbox].field1

or something like that ?
If you're keeping the form open and opening a form on top then you can reference the other form with

Forms!formname!field3.Value

No need for the []
Old 25 April 2006, 11:28 PM
  #7  
spectrum48k
Scooby Regular
Thread Starter
 
spectrum48k's Avatar
 
Join Date: Feb 2006
Posts: 2,519
Likes: 0
Received 0 Likes on 0 Posts
Default

yes, the form is open underneath, but your syntax doesn't apply to a listbox

forms!uderlyingform!listbox.field3

that brings up and error, but I know there's a way to reference each individual field in the row (of the listbox)
Old 26 April 2006, 12:48 PM
  #8  
markr1963
Scooby Regular
 
markr1963's Avatar
 
Join Date: Jun 2002
Location: Perth, Western Australia
Posts: 1,866
Likes: 0
Received 0 Likes on 0 Posts
Default

Try forms!uderlyingform!listbox.column(2). IIRC listbox columns start from 0

so, on the OnClick event for the listbox:
docmd.openform "frmSomeOtherForm"

You could probably use that form's OnOpen or OnCurrent event to populate the textboxes

me.txtName = forms!uderlyingform!listbox.column(2) 'assumimg the 3rd column is the name etc,etc

HTH

Mark
Old 26 April 2006, 04:34 PM
  #9  
spectrum48k
Scooby Regular
Thread Starter
 
spectrum48k's Avatar
 
Join Date: Feb 2006
Posts: 2,519
Likes: 0
Received 0 Likes on 0 Posts
Default

mark, you beauty - I knew it was something like field or column, DOH!!!

.column(2) - thats it!

cheers all
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
JimBowen
ICE
5
02 July 2023 01:54 PM
TylerD529
General Technical
2
09 October 2015 01:53 AM
dpb
Non Scooby Related
14
03 October 2015 10:37 AM
the shreksta
Other Marques
26
01 October 2015 02:30 PM
Littleted
Computer & Technology Related
4
25 September 2015 09:55 PM



Quick Reply: MS Access - put a listbox field into a variable



All times are GMT +1. The time now is 10:26 AM.