Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Trying to write values from a listbox to an unbound table

Posted on 2014-01-17
3
400 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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