?
Solved

Trying to write values from a listbox to an unbound table

Posted on 2014-01-17
3
Medium Priority
?
420 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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

839 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