Bring Data from Access - Validation

G

gatarossi

Dear all,

I'm trying to bring from access to excel the itens_code. I have this
code below, that create a validation in a cell of excel.

But I have a big problem: the excel's validation provide a limited
quantity of data, and I have a lot of data to put like a validation.

I think it is like a filter... but I don't know how to do it and if it
will work...

Could anybody help me with it?

Thanks in advance!!!!

André.

Public Function RunQuery(ByVal strSelect As String, ByVal strFrom As
String, _
ByVal strWhere As String, ByVal strOrderBy, ByVal blnConnected As
Boolean) As ADODB.Recordset

Dim strConnection As String
Dim filenm As String

On Error GoTo ErrorHandler

filenm = ThisWorkbook.Path & "\bd_orcamento.mdb"

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
filenm & ";"

Set RunQuery = New ADODB.Recordset
With RunQuery
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
End With


RunQuery.Open strSelect & " " & strFrom & " " & strWhere & " " &
strOrderBy, strConnection, , , adCmdText

If blnConnected = False Then Set RunQuery.ActiveConnection = Nothing
Exit Function

ErrorHandler:
MsgBox Err.Description
End Function

Sub validation_item_code()
Dim rst As ADODB.Recordset
Dim strValidationList As String

Set rst = RunQuery("Select *", "From table1", "", ";", False)
rst.MoveFirst
strValidationList = rst.Fields("item_code").UnderlyingValue
rst.MoveNext
Do While Not rst.EOF
strValidationList = strValidationList & ", " &
rst.Fields("item_code").UnderlyingValue
rst.MoveNext
Loop
Range("B7:B65536").Validation.Delete
Range("B7:B65536").Validation.Add xlValidateList, , ,
strValidationList

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top