virgilar
asked on
ItemData How to create string array
Hi,
I populate a combobox with the client's firstname and now i am trying to place an alphanumeric record as the index. The field is the client's id. I know that itemData does not support anything but long. Does anyone have a sample that show how the code looks like if an array is created in order to work around that issue. Here is my code below:
'''''The line below is causing the error, i need to be able to create an array like it has been mentioned in previous articles
cmbName.ItemData(cmbName.N ewIndex) = Combo1.ListIndex
Thanks
Andre
Full code
Dim dbs As ADODB.Connection
Dim rs As ADODB.Recordset
Dim firstname As String
Dim LastName As String
Set dbs = New ADODB.Connection
Set rs = New ADODB.Recordset
With dbs
.CursorLocation = adUseClient
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open "C:\Silveus\Forms\Test\Cro pInsMgmt.m db", "admin", ""
End With
With rs
.Open "SELECT FIRSTNAME, CustomerId FROM tblCustomers", dbs, adOpenForwardOnly, adLockOptimistic
If Not .BOF Then
.MoveFirst
Do While Not .EOF
cmbName.AddItem !firstname
'''''The line below is causing the error, i need to be able to create an array like it has been mentioned in previous articles
cmbName.ItemData(cmbName.N ewIndex) = Combo1.ListIndex
.MoveNext
Loop
End If
.Close
End With
dbs.Close
'LoadNames
frmNames.WindowState = 2
I populate a combobox with the client's firstname and now i am trying to place an alphanumeric record as the index. The field is the client's id. I know that itemData does not support anything but long. Does anyone have a sample that show how the code looks like if an array is created in order to work around that issue. Here is my code below:
'''''The line below is causing the error, i need to be able to create an array like it has been mentioned in previous articles
cmbName.ItemData(cmbName.N
Thanks
Andre
Full code
Dim dbs As ADODB.Connection
Dim rs As ADODB.Recordset
Dim firstname As String
Dim LastName As String
Set dbs = New ADODB.Connection
Set rs = New ADODB.Recordset
With dbs
.CursorLocation = adUseClient
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open "C:\Silveus\Forms\Test\Cro
End With
With rs
.Open "SELECT FIRSTNAME, CustomerId FROM tblCustomers", dbs, adOpenForwardOnly, adLockOptimistic
If Not .BOF Then
.MoveFirst
Do While Not .EOF
cmbName.AddItem !firstname
'''''The line below is causing the error, i need to be able to create an array like it has been mentioned in previous articles
cmbName.ItemData(cmbName.N
.MoveNext
Loop
End If
.Close
End With
dbs.Close
'LoadNames
frmNames.WindowState = 2
ASKER
I guess what i am trying to accomplish is populate cmbNames with the client's name and the client's id as the index so i can do a search based on the client's id. The problem is, the clients id is text and the cmbName.ItemData ONLY works with long or integer. I know that there is a way around that by creating a string but i do not know how to do it.
I do not have to populate combo1 with the customer id. The reason i populate combo1 is because i was trying to read the id from there as i selected the name on the cmbName. That did not work.
So i am looking for a way to store the customerid as the index in cmbName. (customerid is a string, that is the problem)
Andre
I do not have to populate combo1 with the customer id. The reason i populate combo1 is because i was trying to read the id from there as i selected the name on the cmbName. That did not work.
So i am looking for a way to store the customerid as the index in cmbName. (customerid is a string, that is the problem)
Andre
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim dbs As ADODB.Connection
Dim rs As ADODB.Recordset
Dim firstname As String
Dim LastName As String
Dim i as Integer
Set dbs = New ADODB.Connection
Set rs = New ADODB.Recordset
With dbs
.CursorLocation = adUseClient
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open "C:\Silveus\Forms\Test\Cro
End With
With rs
.Open "SELECT FIRSTNAME, CustomerId FROM tblCustomers", dbs, adOpenForwardOnly, adLockOptimistic
While Not .EOF
cmbName.AddItem !firstname
cmbName.ItemData(cmbName.N
Combo1.AddItem !CustomerID
.MoveNext
i = i + 1
Wend
.Close
End With
dbs.Close
Set dbs = Nothing
Set rs = Nothing
'LoadNames
frmNames.WindowState = 2