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!
6 5235
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
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.
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.
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: -
Private Sub Form_Load()
-
Dim dbMyDB As Database
-
Dim rsMyRS As Recordset
-
Dim tempList As String
-
-
Set dbMyDB = CurrentDb
-
Set rsMyRS = dbMyDB.OpenRecordset("MyTable", dbOpenDynaset)
-
-
If Not rsMyRS.EOF Then rsMyRS.MoveFirst
-
tempList = Me.lstRecords.RowSource
-
Do While Not rsMyRS.EOF
-
tempList = tempList & ";" & rsMyRS!ID & ";" & rsMyRS!Name
-
rsMyRS.MoveNext
-
Loop
-
-
lstRecords.RowSource = tempList
-
-
End Sub
-
If List Row Source Type is a Table/Query you don't actually use recordsets: -
-
Private Sub Form_Load()
-
Dim strSQL As String
-
-
strSQL = "SELECT [ID], [Name] FROM MyTable"
-
Me.lstRecords.RowSource = strSQL
-
Me.lstRecords.Requery
-
-
End Sub
-
Mary
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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....
|
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,...
|
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...
|
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...
|
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.*,...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |