Jump to content
Fórum Script Brasil
  • 0

Erro estranho vb


gilberto.t

Question

Srs., estou tendo um erro estranho em uma aplicação desenvolvida em vb6 usando access 2003 com adodb. Quando faço a inserção de um registro em um formulario com grid, ele não atualiza o grid. por exemplo, eu insiro o registro e chamo uma funcao que atualiza o grid. quando eu lanço o segundo, ai aparece o primeiro registro, e assim sucessivamente. quando eu conecto o mesmo formulario com o mysql, o erro não acontece. o que pode ser isto?

Agradeço qualquer ajuda!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Obrigado pela força, cara! Segue o codigo.

o primeiro faz a inserção do bd e o segundo atualiza o grid.

==============================================

Private Sub cmdSalvaMB_Click()
'On Error GoTo ErrNro
    If ConsisteMB = False Then
        Exit Sub
    End If
If ConectaServidor() Then
        Set rstRs = New ADODB.Recordset
        iSQl = ""
        iSQl = "SELECT * FROM TABPPPRSP_MB"
        rstRs.Open iSQl, DBConn, adOpenKeyset, adLockOptimistic
        With rstRs
            .AddNew
                rstRs!IDMB = IDMB.Text
                rstRs!mbCRMCREA = mbCRMCREA.Text
                rstRs!mbCtrlClasse = mbCtrlClasse.Text
                rstRs!mbNIT = mbNIT.Text
                rstRs!mbNome = mbNome.Text
                rstRs!mbPeridoAte = mbPeridoAte.Text
                rstRs!mbPeridoDe = mbPeridoDe.Text
                rstRs!funID = funID.Text
            .Update
            Call BuscaMBGrid(funID)
            cmdIncluiRMB.Enabled = True
            cmdSalvaMB.Enabled = False
        End With
        rstRs.Close
End If
    Exit Sub
ErrNro:
    MsgBox "Falha na exclusão do registro!", vbInformation
End Sub
--------------------------------------------------------------------------
Sub BuscaMBGrid(NroFUN As Integer)
    On Error GoTo Err:
    GridRMB.Clear
    GridRMB.Height = 2115
    GridRMB.Top = 240
    GridRMB.Visible = True
    GridRMB.ZOrder
If ConectaServidor() Then
   Set psqRs = New ADODB.Recordset
   iSQl = ""
   iSQl = "SELECT IDMB, mbPeridoDe, mbNome, mbPeridoAte, funID FROM TABPPPRSP_MB WHERE funID = " & NroFUN
   psqRs.Open iSQl, DBConn, adOpenKeyset, adLockOptimistic
        If Not psqRs.EOF = True Then
            GridRMB.Cols = 6
            GridRMB.Rows = psqRs.RecordCount + 2
            i = 1
            Do While Not psqRs.EOF
                GridRMB.TextMatrix(i, 0) = ""
                GridRMB.TextMatrix(i, 1) = psqRs(0)
                GridRMB.TextMatrix(i, 2) = IIf(IsNull(psqRs(1)), "", psqRs(1))
                GridRMB.TextMatrix(i, 3) = IIf(IsNull(psqRs(2)), "", psqRs(2))
                GridRMB.TextMatrix(i, 4) = IIf(IsNull(psqRs(3)), "", psqRs(3))
                GridRMB.TextMatrix(i, 5) = IIf(IsNull(psqRs(4)), "", psqRs(4))
                i = i + 1
                psqRs.MoveNext
            Loop
            With GridRMB
                .ColWidth(0) = 250
                .ColWidth(1) = 0
                .ColWidth(2) = 1200
                .ColWidth(3) = 5400
                .ColWidth(4) = 1200
                .ColWidth(5) = 700
                .TextMatrix(0, 1) = "Nro"
                .TextMatrix(0, 2) = "Dta Inicio"
                .TextMatrix(0, 3) = "Nome"
                .TextMatrix(0, 4) = "Dta.Final"
                .TextMatrix(0, 5) = "FunID"
            End With
            psqRs.Close
        Else
            With GridRMB
                .Clear
                .Cols = 6
                .Rows = 2
                .ColWidth(0) = 250
                .ColWidth(1) = 0
                .ColWidth(2) = 1200
                .ColWidth(3) = 5400
                .ColWidth(4) = 1200
                .ColWidth(5) = 700
                .TextMatrix(0, 1) = "Nro"
                .TextMatrix(0, 2) = "Dta Inicio"
                .TextMatrix(0, 3) = "Nome"
                .TextMatrix(0, 4) = "Dta.Final"
                .TextMatrix(0, 5) = "FunID"
            End With
            psqRs.Close
        End If
End If
    Exit Sub
Err:
    MsgBox Err.Description, vbCritical
End Sub

Edited by kuroi
Adicionar tag CODE
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...