Solved

Trying to write values from a listbox to an unbound table

Posted on 2014-01-17
3
389 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

14 Experts available now in Live!

Get 1:1 Help Now