Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Manipular recordset


Humm

Question

então, tenho uma consulta que já me retorna os valores que quero..

quero um codigo que me de uma msgbox para cada registro dessa consulta.. como fazer?

acho que tem que ser com o for each campo in conjunto

mas ainda não entendi como chegar até ai..

Dim strQ As String
        Dim db As Database
        Dim rs As DAO.Recordset
        
        strQ = "SELECT prod, qtde, preço FROM TIK_ITENS"
        
        Set db = CurrentDb()
        Set rs = db.OpenRecordset(strQ, dbOpenSnapshot)
        
        With rs
        .MoveFirst
            For Each prod In rs
                MsgBox prod & " " & QTDE & " " & preço
                
            Next prod
        End With

não ta dando certo, da erro na linha do set rs

erro em tempo de execucao 3061

parametros insuficientes. eram esperados 1

alguém da um help?

Edited by Humm
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Tenta isso, não testei

Sub TestIt()

Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset

Set conn = CurrentProject.Connection
Set cmd = New ADODB.Connection
cmd.ActiveConnection = conn

cmd.CommandText = "SELECT TI.prod, TI.qtde, TI.preço FROM TIK_ITENS AS TI"
Set rs = cmd.Execute

rs.MoveFirst
Do While Not rs.EOF
    MsgBox rs("prod") & vbNewLine & _
        rs("qtde") & vbNewLine & _
        rs("preço")
        
    rs.MoveNext
Loop
        
cmd.ActiveConnection.Close
rs.Close

Set rs = Nothing
Set cmd = Nothing
Set conn = Nothing

End Sub

Edited by Iceguy
Link to comment
Share on other sites

  • 0

HEHE... Falha Técnica

Corrigi...

Sub TestIt()

Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset

Set conn = CurrentProject.Connection
Set cmd = New ADODB.Command
cmd.ActiveConnection = conn

cmd.CommandText = "SELECT TI.prod, TI.qtde, TI.preço FROM TIK_ITENS AS TI"
Set rs = cmd.Execute

If rs.EOF And rs.BOF Then
    GoTo Sair
End If

rs.MoveFirst
Do While Not rs.EOF
    MsgBox rs("prod") & vbNewLine & _
        rs("qtde") & vbNewLine & _
        rs("preço")
        
    rs.MoveNext
Loop
        
Sair:
    rs.Close
    cmd.ActiveConnection.Close
    
    Set rs = Nothing
    Set cmd = Nothing
    Set conn = Nothing

End Sub

Link to comment
Share on other sites

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.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...