none
insert value from a unbound text box RRS feed

  • Question

  • hi

    how do i insert the value of unbound text box in my form to the last record in a table(not new record)

    i want to do this on dao 

    Private Sub pic_Click()
    Dim rstCategories As Recordset
    Set rstCategories = CurrentDb.OpenRecordset(Name:="my table name", Type:=RecordsetTypeEnum.dbOpenDynaset)
    With rstCategories
        With rstCategories
        End With

    With rstCategories
    .MoveLast 0


    End With

    With rstCategories
        .Edit
        ![my failed name] = "the value of the text box"
        
    End With
    End With
    DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name
    DoCmd.OpenForm FormName:="next form", View:=acNormal
    End Sub

    • Edited by eshay1 Thursday, August 13, 2015 3:08 PM error
    Thursday, August 13, 2015 3:05 PM

Answers

  • You need to add .update after you assign the value.

    .Edit
    .Fields!FieldName = Value
    .Update
    .Close

    Private Sub pic_Click()
         
        On Error GoTo Err_Process
        
        Dim rst1 As Recordset
        Dim dbs1 As Database
        
        Set dbs1 = CurrentDb
        Set rst1 = dbs1.OpenRecordset("my table name", dbOpenDynaset)
        
        With rst1
            If (Not .EOF) Then
               .MoveLast
               .Edit
               .Fields![my failed name] = Me.txtInput
               .Update
            End If
    .Close End With DoCmd.Close acForm, Me.Name DoCmd.OpenForm "next form", acNormal Exit_Process: Set dbs1 = Nothing Set rst1 = Nothing Exit Sub Err_Process: MsgBox Err.Number & " " & Err.Description, vbExclamation, "Error" Resume Exit_Process End Sub




    • Edited by RunningManHD Thursday, August 13, 2015 3:21 PM
    • Marked as answer by eshay1 Thursday, August 13, 2015 10:34 PM
    Thursday, August 13, 2015 3:13 PM

All replies

  • You need to add .update after you assign the value.

    .Edit
    .Fields!FieldName = Value
    .Update
    .Close

    Private Sub pic_Click()
         
        On Error GoTo Err_Process
        
        Dim rst1 As Recordset
        Dim dbs1 As Database
        
        Set dbs1 = CurrentDb
        Set rst1 = dbs1.OpenRecordset("my table name", dbOpenDynaset)
        
        With rst1
            If (Not .EOF) Then
               .MoveLast
               .Edit
               .Fields![my failed name] = Me.txtInput
               .Update
            End If
    .Close End With DoCmd.Close acForm, Me.Name DoCmd.OpenForm "next form", acNormal Exit_Process: Set dbs1 = Nothing Set rst1 = Nothing Exit Sub Err_Process: MsgBox Err.Number & " " & Err.Description, vbExclamation, "Error" Resume Exit_Process End Sub




    • Edited by RunningManHD Thursday, August 13, 2015 3:21 PM
    • Marked as answer by eshay1 Thursday, August 13, 2015 10:34 PM
    Thursday, August 13, 2015 3:13 PM
  • tnx you very much. i was stuck for a week and asked in other forums

    and i got confused answers

    your code work perfect. and you wrote at in so easy way to just past at in my data base

    tnx again 

     
    Thursday, August 13, 2015 10:33 PM