Rizwan Safdar
Rizwan Safdar

Reputation: 135

What is wrong with this VBA Code

Please tell me what is wrong with this code. It shows error... "The rowsourcetype property must be set to value list to use this"

Private Sub Form_Load()
     Dim db As DAO.Database
     Dim rs As DAO.Recordset
     Dim strSQL As String, strItem As String

    strSQL = "SELECT CustomerID, CompanyName FROM Customers"
    Set db = CurrentDb
    Set rs = db.OpenRecordset(strSQL)
    Do Until rs.EOF
         strItem = rs.Fields("CustomerID").Value & ";" _
         & rs.Fields("CompanyName").Value
    Me.List1.AddItem strItem      ' Row Source Type must be Value List
    rs.MoveNext

    Loop
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    End Sub

Upvotes: 1

Views: 503

Answers (1)

Max
Max

Reputation: 759

Go to the properties of the list-item, in data you find the property "Row Source Type" and set this to "Value list". Or you can do ths in the code by putting

Me.Liste3.RowSourceType = "Value List"

right at the start of your code after the line Dim strSQL As String, strItem As String

Hope this helps! Max

Upvotes: 4

Related Questions