Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 8th, 2004, 06:28 AM
Authorized User
 
Join Date: Jul 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help! trying to insert data into a table


Private Sub cmdAdd_Click()
Dim rs as new ADODB.recordsetI have two list boxes called "lstdates" which contain 600 dates and a list box called "lstboats" which contain 60 boat names, i want to be able to select multiple dates and multiple boats and insert them into a table called tblboatstodates fieldss boatid and checkdateid, the following code:

Dim varBoatID
Dim varCheckDateID



    rs.Open "tblBoatstoDates", CurrentProject.Connection, adOpenStatic, adLockOptimistic
    For Each varBoatID In lstBoats.ItemsSelected
        For Each varCheckDateID In lstDates.ItemsSelected

            rs.AddNew

            rs!BoatID = varBoatID
            rs!Checkdateid = varCheckDateID
            rs.Update
        Next
    Next
    rs.Close


End Sub

the code works but is inputting the order they appear

Example: say if i had 10 dates in the list box"lstdates" ranging from 01 Jan 04 -- 10 Jan 04

 (this dates come from a table called tblcheckdate1 and the unique key is DateID)
01 Jan 04 = DATEID 26
02 Jan 04 = DATEID 27
03 Jan 04 = DATEID 28
04 Jan 04 = DATEID 29
05 Jan 04 = DATEID 30
06 Jan 04 = DATEID 31
..etc

BUT as 01 Jan 04 appears first in the list its value =0 when inputting into tblboatstodates
02 Jan 04 =1
03 Jan 04 =2

this is the same for lstboats



 
Old January 8th, 2004, 09:11 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

So what exactly is the problem? Do you want 01 Jan 04 to be DateID 26 and not be zero in the table? I'm not sure what the problem is.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old January 8th, 2004, 10:11 AM
Authorized User
 
Join Date: Jul 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the dates come from a table called tblcheckdate1 it has two fields :: checkdateid and checkdate

Example

checkdateid | checkdate
--------------------------
26 01 Jan 04
27 02 Jan 04

the problem is that 01 Jan 04 appears in the list box (lstdates) as the first record, so when i press cmdadd

0 gets entered into tblboatstodates.checkdateid where it should be 26

-
David

 
Old January 8th, 2004, 11:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

On your listbox that lists the dates, make the rowsource of the list box not only the dates but the CheckDateID as well. Make the listbox show two columns (Column Count property = 2): CheckDateID and Date. Set the bound column to Column 1 (CheckDateID). Set the column width of Column 1 to Zero (i.e. invisible) and set the column width of Column 2 to whatever you want. Set the list width = to the width of Column 2. When the user picks a date, Access will take the CORRECT CheckDateID and store it in your table.

If your list box is called, for example, lstMyListBox then CheckDateID will be equal to lstMyListBox.Column(0) and the date will be equal to lstMyListBox.Column(1)


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling unique data from 1 table insert into anoth shawn.bordeaux Classic ASP Basics 0 November 9th, 2008 10:11 PM
Insert table records into another table. hewstone999 Access VBA 2 March 5th, 2008 11:01 AM
DTS does not insert data into table kathytran20022002 SQL Server DTS 3 February 14th, 2006 02:59 PM
How do I insert data into multiple table ? bmalex1 PHP How-To 0 February 2nd, 2006 02:43 PM
how to insert into SQL table p2ptolu Classic ASP Databases 1 June 17th, 2005 06:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.