473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

recordset will not assign column values listbox columns

27
I am trying to run through a tutorial on recordsets, so I am following the tutorial here:

http://www.devdos.com/vb/lesson4.shtml



I have made the table as described, and tried to run this code:



Option Compare Database
Dim dbMyDB As Database
Dim rsMyRS As Recordset



Private Sub Form_Load()


Set dbMyDB = CurrentDb
Set rsMyRS = dbMyDB.OpenRecordset("MyTable", dbOpenDynaset)

If Not rsMyRS.EOF Then rsMyRS.MoveFirst
Do While Not rsMyRS.EOF
lstRecords.AddItem rsMyRS!Name
lstRecords.ItemData(lstRecords.NewIndex) = rsMyRS!ID
rsMyRS.MoveNext
Loop

End Sub


However, I am getting an error with the .newindex command. I assume what this line of code is trying to do is assign the ID number of the Name field to the corresponding listbox entry. Is there another way to do it?

Thank you!
Dec 11 '06 #1
6 5235
MMcCarthy
14,534 Expert Mod 8TB
Are you designing in VB or VBA. The following code appears to be Visual Basic. If that's the case then you will have to post this question in the Visual basic forum.

If however, you are using Access forms and VBA let me know more details of the form, listbox and the table you mentioned.

Mary
Dec 11 '06 #2
psuaudi
27
I am using VBA. All I have is a simple form that has the listbox that is tied to a table with 3 fields: ID(autonumber), Name(text), and Phone(text).

I'm simply doing this as an exercise to try to learn more about recordsets.
Dec 12 '06 #3
NeoPa
32,556 Expert Mod 16PB
I am using VBA. All I have is a simple form that has the listbox that is tied to a table with 3 fields: ID(autonumber), Name(text), and Phone(text).

I'm simply doing this as an exercise to try to learn more about recordsets.
I'm sorry.
I tried to look at the tutorial and found the code.
Unfortunately I couldn't find anything in Help that dealt with .AddItem or the .NewIndex value.
Maybe ask at the site that has the tutorial.
Good for you to be doing what you're doing though. If you find you can't get on with that, we do have links in the Access section to tutorials and helpful explanations for various items including RecordSet processing.
Dec 12 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
I am using VBA. All I have is a simple form that has the listbox that is tied to a table with 3 fields: ID(autonumber), Name(text), and Phone(text).

I'm simply doing this as an exercise to try to learn more about recordsets.
The code you are using, .AddItem and .NewIndex are VB functions. It is done differently in VBA.

See below ...

If List Row Source Type is a value list:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  Dim dbMyDB As Database
  3.  Dim rsMyRS As Recordset
  4. Dim tempList As String
  5.  
  6.    Set dbMyDB = CurrentDb
  7.    Set rsMyRS = dbMyDB.OpenRecordset("MyTable", dbOpenDynaset)
  8.  
  9.    If Not rsMyRS.EOF Then rsMyRS.MoveFirst
  10.    tempList = Me.lstRecords.RowSource
  11.    Do While Not rsMyRS.EOF
  12.       tempList = tempList & ";" &   rsMyRS!ID & ";" &  rsMyRS!Name
  13.       rsMyRS.MoveNext
  14.    Loop
  15.  
  16.    lstRecords.RowSource = tempList
  17.  
  18. End Sub
  19.  
If List Row Source Type is a Table/Query you don't actually use recordsets:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3.  Dim strSQL As String
  4.  
  5.    strSQL = "SELECT [ID], [Name] FROM MyTable"
  6.    Me.lstRecords.RowSource = strSQL
  7.    Me.lstRecords.Requery
  8.  
  9. End Sub
  10.  
Mary
Dec 12 '06 #5
psuaudi
27
I guess I am still struggling with using recordsets and perhaps some of the more intimate details of using combolists. I'm not sure what direction I should head in next.
Dec 12 '06 #6
NeoPa
32,556 Expert Mod 16PB
I guess I am still struggling with using recordsets and perhaps some of the more intimate details of using combolists. I'm not sure what direction I should head in next.
Links to useful sites is a good place to start.
Dec 12 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dana | last post by:
I have a form with a couple of dropdown fields. the dropdown fields get the value from one table which is a reference table. The table consists of 3 columns - type, id, name. An example would...
1
by: melanie | last post by:
Hi, I open a recordset with a SQL query as its source. Then, i set the listbox.recordset = to the recordset i just opened. But, the fields appear in the listbox columns in a different order...
4
by: Giulio | last post by:
Hello, I have a continuous form with a combo box inside. From the combo box I can pick some values which, by the "after-update" event, change some other combo box values determined by a query....
7
by: Douglas Buchanan | last post by:
I cannot access certain column values of a list box using code. I have a list box 'lstPrv' populated by the query below. SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,...
22
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create...
5
by: Rated R1 | last post by:
I wrote this before in the NGs, so I am going to paste the responses that I got and see if someone can please help me. Email me and we can set something up as Id even be willing to pay for your...
1
by: Edward | last post by:
I've recently migrated the back end of one of my client's applications from Access to SQL Server. One of the forms is based on an Access query thus: SELECT dbo_tblDistributionDetail.*,...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
6
by: chopin | last post by:
I am working in Access 2003 in Windows XP. I am using Visual Basic for Applications, using DAO to write my modules. What I need to do is write a module that will compare each row to see if they are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.