How to update a view (Data sheet as subform), extracting data from a query of it In VBA ACCESS

0

I have the following code, the data sheet of the subform is the same that I have in my main form, it is supposed that only a Requery is required but it does not update me, it tells me that one of the fields is out of range:

    Private Sub cmdAceptar_Click()
On Error GoTo Handler

    Dim SQLUpdate As String
    Dim rs As ADODB.Recordset
    Dim cnn As ADODB.Connection

    Set cnn = Application.CurrentProject.Connection
    Set rs = New ADODB.Recordset

    With rs
        .ActiveConnection = cnn
        .LockType = adLockReadOnly
        .CursorType = adOpenStatic
        .Open ("SELECT SendDate, " & _
                        "Guidenumber, " & _
                        "GuideStatus, " & _
                        "UserUpdateGuide, " & _
                        "DateUpdateGuide " & _
               "FROM Vt_guides " & _
               "WHERE GuideID = " & Forms!frm_guides!GuideID & " ")
    End With

    rs.MoveFirst

    If rs.EOF Then
        MsgBox "Ha ocurrido un error...", vbExclamation + vbOKOnly, "Cataciones Muestras"
        Exit Sub
    Else

        SQLUpdate = vbNullString
        SQLUpdate = "UPDATE Cataciones_muestras " & _
                    "SET SendDate = " & rs!SendDate & ", " & _
                         "GuideNumber = " & rs!GuideNumber & ", " & _
                         "GuideStatus = " & rs!GuideStatus & ", " & _
                         "UserUpdateGuide = " & rs!UserUpdateGuide & ", " & _
                         "DateUpdateGuide = " & rs!DateUpdateGuide & " " & _
                    "WHERE MT_mov = " & Me.Vista_cataciones_muestras!MT_mov & " "

        DoCmd.RunSQL SQLUpdate, True

        Me.Vista_cataciones_muestras.Form.Requery

    End If

    DoCmd.Close acForm, "frm_cataciones_muestras", acSaveYes

Handler:
    ErrorGeneral

    Set rs = Nothing
    Set cnn = Nothing

 End Sub

This is the code of the button that is in the main form, as I am using the same view in the main one, only with a different name, in the form above it is called "Vista_cataciones_samples" and here it is called "Vista_samples"

Private Sub cmdCatmu_Click()

    DoCmd.OpenForm "frm_cataciones_muestras", acNormal, , , acFormEdit, acDialog
    Me.Vista_muestras.Enabled = True 'Test
    Me.Vista_muestras.Form.RecordsetType = 4 'Test
    Me.Vista_muestras.Form.Requery 'Aqui solo hago Requery

End Sub
    
asked by Josue Roman 28.03.2018 в 02:35
source

0 answers