cannot populate listbox

Wesselcram

New member
Local time
Today, 21:19
Joined
Jan 8, 2014
Messages
8
Hi,

First of all thanks for all the many, many helpfull information these forums are providing me. However I've uncountered a problem im not able to solve just yet.

I want to fill my 2-column listbox on a form with the help of the following VBA code:

Option Compare Database

Private Sub Form_Load()

Dim proefsel As Integer
Dim nproducts As Integer
Dim i As Integer

proefsel = [Form_begin formulier].lijstproefomschrijving.Value
Set rst = CurrentDb.OpenRecordset("SELECT * FROM termen WHERE proefnr = " & proefsel & "")

i = 0
Me.lstproducts.Clear
rst.MoveFirst

Do Until rst.EOF
Me.lstproducts.AddItem
Me.lstproducts.List(i, 0) = rst![NR]
Me.lstproducts.List(i, 1) = rst![termen]
i = i + 1
rst.MoveNext
Loop

End Sub

When i run the code i get a compile error on the code in bolt. I am using access 2010.

Thanks in advance!

Wessel.
 
Hello Wessexlcram, Welcome to AWF :)

Why could you just not do something like..
Code:
Option Compare Database
Option Explicit 

Private Sub Form_Load()
    Me.lstproducts.RowSource = "SELECT NR, termen FROM termen WHERE proefnr = " & Forms![Form_begin formulier].lijstproefomschrijving)
End Sub
 
Works like a dream! Thanks!

Wessel.
 

Users who are viewing this thread

Back
Top Bottom