Ir para conteúdo
Fórum Script Brasil
  • 0

dao para ado


gianne

Pergunta

Eu digito o codigo no text1, e click no enter para procurar o codigo e retornar os dados no grid.

mais está dando erro RUN-TIME ERROR 91: OBJETO VARIABLE OR WITH BLOCK VARIABLE NOT SET

A linha do erro está em vermelho

Sub CarregaGrid()

Do While Grid1.Rows > 1

Grid1.Rows = Grid1.Rows - 1

Loop

Grid1.Rows = Grid1.Rows + 1

If Len(Trim(Text1)) > 0 Then

Dim selection2 As String

selection2 = "select * from Estamparia where numos = '" & Text1 & "' Order by Contador"

''Set db = OpenDatabase(App.Path & "\bases\Base34.mdb")

''Set tb = db.OpenRecordset(selection2)

''Set tbLocal = db.OpenRecordset(selection2

Set tb = ExecutaRS(selection2)

If tb.BOF And tb.EOF Then

'MsgBox "O. S. não apontada. Favor verificar.", vbInformation, "Atenção"

Cont = 0

VarMetragem = 0

Label13 = "ÚLTIMA ACUMULADA : 0,00"

Else

Cont = 0

VarMetragem = 0

result = 0

Grid1.Row = 1

Do While tb.EOF = False

With Grid1

If Len(Trim(tb(10))) = 0 Then

.CellBackColor = &H80000005

.Col = 0

.Text = tb(6)

.Col = 1

.Text = tb(7)

.Col = 2

.Text = tb(3)

VarMetragem = tb(9) - result

result = tb(9)

.Col = 3

.Text = VarMetragem

.Col = 4

.Text = tb(9)

Label13 = "ÚLTIMA ACUMULADA : " & Format(tb(9), "#,##0.00")

Set Grid1.DataSource = tbLocal

Grid1.Refresh

.Col = 5

.Text = tb(0) 'Contador

Else

.Col = 0

.Text = tb(10)

.Col = 1

.Text = tb(10)

.Col = 2

.Text = tb(10)

.Col = 3

.Text = tb(10)

.Col = 4

.Text = tb(10)

.Col = 5

.Text = tb(0) 'Contador

With tbLocal

'.Edit

'.Fields(8) = VarMetragem

'.Update

.MoveNext

End With

Dim irow As Integer

LinhadaGrid = .Row

With Grid1

.Row = LinhadaGrid

.Col = 0

.RowSel = LinhadaGrid

.ColSel = 4

End With

For irow = Grid1.Row To Grid1.RowSel

Grid1.MergeRow(irow) = True

Next

Grid1.MergeCells = 2

.CellBackColor = &HE0E0E0

End If

End With

VarMetragem = 0

Grid1.Rows = Grid1.Rows + 1

Grid1.Row = Grid1.Rows - 1

tb.MoveNext

Cont = Cont + 1

Loop

If Cont = 0 Then Label8 = ""

If Cont = 1 Then Label8 = "1 Lançamento."

If Cont > 1 Then Label8 = Cont & " Lançamentos."

Dim selection1 As String

selection1 = "Select * from Estamparia where Dia = '" & Label5 & "' "

''Set db = OpenDatabase(App.Path & "\Bases\Base34.mdb")

''Set tb = db.OpenRecordset(Selection)

Set tb = ExecutaRS(selection1)

With tb

If .BOF And .EOF Then

Else

Dim TotalDia As Single

TotalDia = 0

Do While .EOF = False

If UCase(.Fields(2)) = UCase(Trim(Text6)) Then

TotalDia = TotalDia + .Fields(8)

End If

.MoveNext

Loop

Label8 = Label8 & " - Total do dia : " & Format(TotalDia, "#,##0.00") & " metros."

End If

End With

End If

End If

End Sub

Link para o comentário
Compartilhar em outros sites

12 respostass a esta questão

Posts Recomendados

  • 0

mas gianne, o recordset tbLocal esta aberto quando chega nessa linha??

porque la em cima, a linha q executa ele, esta comentada:

''Set tbLocal = db.OpenRecordset(selection2

e você ta executando, na verdade o tb. não deveria ser ele q você devia passar para o DataSource do grid??

e veja a dica do macedo tb.

Link para o comentário
Compartilhar em outros sites

  • 0
Guest --gianne --

''Set db = OpenDatabase(App.Path & "\bases\Base34.mdb")

''Set tb = db.OpenRecordset(selection2)

No access esta assim

Alterei para SQL, ficou assim

set db = abrecn

criei um modulo conexao , que tem uma function abrecn...que abre a conexao com servidor

set tb = db.execute (selection2)....o primeiro erro e nesta linha.....

Link para o comentário
Compartilhar em outros sites

  • 0
Guest --Gianne --

oi....o codigo ficou assim....

O ERRO ESTA DANDO NO EXECUTE....

COPILE ERROR EXPECTED FUNCTION OR VARIABLE :rolleyes:

AGRADEÇO....PELA AJUDA...PRECISO FAZER ESSE PROJETO URGENTE...

Sub CarregaGrid()
Do While Grid1.Rows > 1
    Grid1.Rows = Grid1.Rows - 1
Loop
Grid1.Rows = Grid1.Rows + 1

If Len(Trim(Text1)) > 0 Then
    Selection = "select * from Estamparia where numos =  '" & Text1 & "' Order by Contador"
    Set db = abrecn
    Set tb = db.execute(Selection)
    Set tbLocal = db.execute(Selection)
    If tb.BOF And tb.EOF Then
        'MsgBox "O. S. não apontada. Favor verificar.", vbInformation, "Atenção"
        Cont = 0
        VarMetragem = 0
        Label13 = "ÚLTIMA ACUMULADA : 0,00"
    Else
        Cont = 0
        VarMetragem = 0
        result = 0
        Grid1.Row = 1
        Do While tb.EOF = False
            With Grid1
                If Len(Trim(tb(10))) = 0 Then
                .CellBackColor = &H80000005
                    .Col = 0
                    .Text = tb(6)
                    
                    .Col = 1
                    .Text = tb(7)
                    
                    .Col = 2
                    .Text = tb(3)
                    
                    VarMetragem = tb(9) - result
                    result = tb(9)
                    
                    .Col = 3
                    .Text = VarMetragem
                                        
                    .Col = 4
                    .Text = tb(9)
                    Label13 = "ÚLTIMA ACUMULADA : " & Format(tb(9), "#,##0.00")
                    
                    With tbLocal
                        .Edit
                        .Fields(8) = VarMetragem
                        .Update
                        .MoveNext
                    End With
                    .Col = 5
                    .Text = tb(0)   'Contador
                Else
                    .Col = 0
                    .Text = tb(10)
                    
                    .Col = 1
                    .Text = tb(10)
                    
                    .Col = 2
                    .Text = tb(10)
                    
                    .Col = 3
                    .Text = tb(10)
                    
                    .Col = 4
                    .Text = tb(10)
                    
                    .Col = 5
                    .Text = tb(0)   'Contador
                    With tbLocal
                        .Edit
                        .Fields(8) = VarMetragem
                        .Update
                        .MoveNext
                    End With
                    Dim irow As Integer
                    LinhadaGrid = .Row
                    With Grid1
                        .Row = LinhadaGrid
                        .Col = 0
                        .RowSel = LinhadaGrid
                        .ColSel = 4
                    End With
                    For irow = Grid1.Row To Grid1.RowSel
                        Grid1.MergeRow(irow) = True
                    Next
                    Grid1.MergeCells = 2
                    .CellBackColor = &HE0E0E0
                End If
            End With
            VarMetragem = 0
            Grid1.Rows = Grid1.Rows + 1
            Grid1.Row = Grid1.Rows - 1
            tb.MoveNext
            Cont = Cont + 1
        Loop
        If Cont = 0 Then Label8 = ""
        If Cont = 1 Then Label8 = "1 Lançamento."
        If Cont > 1 Then Label8 = Cont & " Lançamentos."
        
        Selection = "Select * from Estamparia where Dia = '" & Label5 & "' "
        Set db = abrecn
        Set tb = db.execute(Selection)
        
        With tb
            If .BOF And .EOF Then
            Else
                Dim TotalDia As Single
                TotalDia = 0
                Do While .EOF = False
                    If UCase(.Fields(2)) = UCase(Trim(Text6)) Then
                        TotalDia = TotalDia + .Fields(8)
                    End If
                    .MoveNext
                Loop
                
                Label8 = Label8 & " - Total do dia : " & Format(TotalDia, "#,##0.00") & " metros."
            End If
        End With
    End If
    
End If
    
End Sub

Editado por kuroi
Adicionar Tag CODE
Link para o comentário
Compartilhar em outros sites

  • 0

é, ta estranho isso.

o erro é no execute ou no abrecn?? o q é abrecn?? é uma sub?? qual o codigo dela??

qual o codigo de quando você abre a conexao??

e só uma dica, não tem a ver com esse erro, mas esse codigo aqui:

If tb.BOF And tb.EOF Then

acho q o certo seria Or em vez de And não?? porque ele nunca vai estar no comeco e no final do arquivo ao mesmo tempo.

Link para o comentário
Compartilhar em outros sites

  • 0
Guest --Gianne --

abrecn e uma function

Public Const CNSTRING = "Provider=SQLOLEDB.1;Data Source=ffff;Initial Catalog=ffff;User ID=fff;Password=ffff;"

Public Function AbreCN() As ADODB.Connection
    
    Dim conn As New ADODB.Connection
    conn.ConnectionString = CNSTRING
    conn.Open
    Set AbreCN = conn
    
End Function

Editado por kuroi
Adicionar Tag CODE
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...