Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox to another listbox 2

Status
Not open for further replies.

Cantor

Programmer
Apr 27, 2000
28
0
0
CA
Hi,In my form I've 2 listbox: ListBox1 and ListBox2. ListBox1 is full and ListBox2 is empty. What I want dto do is when I double click on an item in ListBox1, the item is sent in ListBox2.Antoher way I think to do that was a command button who put the item selected in ListBox1 and put it in ListBox2.Looks like easy no? but i'm still wondering.Any help is welcome,Cantor
 
On double click of Listbox1 you have to add an event that does the following:<br>1) adds the selected record to the recordsource of Listbox2.<br>2) deletes the selected record from recordsource of Listbox1.<br>3) refreshes Listbox1 and Listbox2.<br>That's all <p>Sandeep Anand<br><a href=mailto:sandeep@matatechnologies.com>sandeep@matatechnologies.com</a><br><a href= Technologies</a><br>visit
 
Can you give me the code to achieve this in Access 97? Shane Brennan

'-----------------------
' ICQ#125948839
' Emails: sab149@icqmail.com
' shanebrennan@postmaster.co.uk
' Personal ICQ Comms. Centre: wwp.icq.com/125948839
'
' Personal WebPage:
 
Hi Shane and Cantor!

Probably the easiest way is to add a yes/no field to the table that the information is coming, setting no as the default for the field. Set the row source for the list boxes:

List1:

Select YourFields From YourTable Where SelectionField = False

List2:

Select YourFields From YourTable Where SelectionField = True

Then, in the double click event for the first list box use:

Dim rst As DAO.Recordset
Dim sql As String

sql = &quot;Select SelectionField From YourTable Where IDField = '&quot; & List1.Value & &quot;'&quot;
Set rst = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
rst!SelectionField = True
List1.Requery
List2.Requery

Set rst = Nothing

You will use similar VBA in the double Click event for List2 except you will change the SelectionField to False. My code assumes that the bound field will be the ID field and that the ID field is a text field.

hth
Jeff Bridgham
bridgham@purdue.edu
 
I've put similar code into the click event of my 1st program and I get the following run-time error:

-----------------------------------------------
run-time error '3020'

Update or CancelUpdate without AddNew or Edit
-----------------------------------------------


Code I used is:

-------------------------------------------------------
Private Sub listNotSelected_Click()
Dim rst As DAO.Recordset
Dim sql As String

sql = &quot;Select req From tblMemberOftest Where [tblMemberOftest].[contactid] = '&quot; & listNotSelected.Value & &quot;'&quot;
Set rst = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
rst![Req] = True
' listNotSelected.Requery
End Sub

--------------------------------------

tblMemberOftest is the source Table.

Any ideas why this won't work?

Shane Shane Brennan

'-----------------------
' ICQ#125948839
' Emails: sab149@icqmail.com
' shanebrennan@postmaster.co.uk
' Personal ICQ Comms. Centre: wwp.icq.com/125948839
'
' Personal WebPage:
 
Hi Again!

Let me say OOPS!!

rst.Edit
rst![Req] = True
rst.Update

That should do it, sorry!
Jeff Bridgham
bridgham@purdue.edu
 
Thanks - I worked it out.... Blooming difficult to find out how. I expected the recordset to be automatically updateable.

I guess that's just one of the &quot;Features&quot; of Access :(

Shane Shane Brennan

'-----------------------
' ICQ#125948839
' Emails: sab149@icqmail.com
' shanebrennan@postmaster.co.uk
' Personal ICQ Comms. Centre: wwp.icq.com/125948839
'
' Personal WebPage:
 
Hi!

I agree, that one came out of the Howtomakeitharder committee! :)

Jeff Bridgham
bridgham@purdue.edu
 
Jeff,

Didn't it also come out of the Howtoproducelotsofduplicateddata committee?

Ed Metcalfe.
 
Hi Ed!

LOL With the assistance of the Storethewronginfo committee!

Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top