Solved

Trying to write values from a listbox to an unbound table

Posted on 2014-01-17
3
392 Views
Last Modified: 2014-01-18
I'm trying to write values from a listbox to an unbound table.

My code isn't working.

Here it is:

    Dim RS As DAO.Recordset
        Set RS = CurrentDb.OpenRecordset("tblReady")
            RS.AddNew
            RS!Bay = Forms!frmPlanted.ListBayQty.Bay
            RS!ReadyQty = Forms!frmPlanted.ListBayQty.ReadyQty
            RS.Update

????
0
Comment
Question by:SteveL13
3 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 39789919
You refer to columns in a listbox by their index (which is zero-based):

Dim RS As DAO.Recordset
        Set RS = CurrentDb.OpenRecordset("tblReady")
            RS.AddNew
            RS!Bay = Forms!frmPlanted.ListBayQty.Column(0)
            RS!ReadyQty = Forms!frmPlanted.ListBayQty.Column(1)
            RS.Update

If the code is running on frmPlanted:

            RS.AddNew
            RS!Bay = Me.ListBayQty.Column(0)
            RS!ReadyQty = Me.ListBayQty.Column(1)
            RS.Update

Obviously you'd have to change the Column(x) values to match those in your listbox.
0
 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 250 total points
ID: 39789920
Try this
   Dim RS As DAO.Recordset
        Set RS = CurrentDb.OpenRecordset("tblReady")
            with RS
                 .AddNew
                 !Bay = Forms!frmPlanted.ListBayQty.Bay
                 !ReadyQty = Forms!frmPlanted.ListBayQty.ReadyQty
                 .Update
            end witn
      RS.Close

set RS= Nothing

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39789930
What is he need for this?

I mean, ...there is a way to do this as you ask, ...

But if you state your ultimate goal, we may be able to provide a more efficient method...

For example, it should be far easier to insert the listbox "source" to a table.

But again, if the listbox source is already a table/query, ...what is the need to export it to another table?

JeffCoachman
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now