简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM