• 0
Sign in to follow this  
felipe.passos

DUVIDA - SELECT VBA LIGANDO COM ACCESS

Question

Boa tarde Pessoal,

Me ajudem nesse SELECT, quero trazer toda a lista que tem no BD do Access para o Excel usando o VBA

Nesse meu codigo está dando erro.

Option Explicit
Global Db As Database
Global RSt As Recordset
Global RSt2 As Recordset
Global rstp As Recordset
Global RstAux As Recordset
Global UserName, SQL, SQL1 As String

Public Sub Busca_eventos()

Dim Db2 As Database

Dim RSt2 As Recordset
Dim linha As Long ''define a linha onde será inserido
Dim Palavra As Variant

'A cada nova pesquisa o conteúdo anterior será apagado
Range("A6:f1000").Select
Selection.ClearContents
Cells(1, 1).Select

'define de onde buscar o registro:
Palavra = Sheets("Formulário").Range("a1").Value
Palavra = UCase(Palavra)

'ThisWorkbook.Path & "\BD_Orcamento.mdb"

Set Db2 = OpenDatabase(ThisWorkbook.Path & "BD_Orcamento.mdb" & ThisWorkbook.Name, False, False, "Excel 8.0")

Set RSt2 = Db2.OpenRecordset("SELECT * FROM Registro")


'define em qual linha começar:
 linha = 5
'enquanto não houver erro:
While Not RSt2.EOF
linha = linha + 1
Cells(linha, 1) = RSt2("armario")
Cells(linha, 2) = RSt2("caixa")
Cells(linha, 3) = RSt2("prateleira")
Cells(linha, 4) = RSt2("conteudo")
RSt2.MoveNext
Wend
'fecha o banco
RSt2.Close
Db2.Close
       
End Sub

 

E também tenho duvida de como fazer UPDATE

 

Obrigado!

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this