Results 1 to 4 of 4
  1. #1
    JakubM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    2

    Saving the value in the text field after the closed form

    As in the title, my problem is the disappearing values in the text box after closing the form. I wrote a macro



    Code:
    Public Sub Form_Close()
    CurrentDb.Execute "INSERT INTO tbl_values" _
    & "(column_value_1,column_value_2,column_value_3,column_value_4,column_value_5) VALUES" _
    & "('" & text_field_1 & "','" & text_field_2 & "','" & text_field_3 & "','" & text_field_4 & "','" & text_field_5 & "');"
    End Sub
    When I close form it gets these values and inserts into the table but I can't take back this values when I open the form.
    Could someone help me?
    Maybe it can be done in a different way

    Regards and thanks for help

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    14,908
    Welcome to the forum.
    What exactly does this mean?
    but I can't take back this values when I open the form
    An observation:

    Naming table fields
    column_value_2,column_value_3.... may be meaningful to you as you work with the table,
    but it will be difficult in future if someone else or you yourself has to change something.
    Use meaningful names for fields and objects

    Good luck with your project.

  3. #3
    JakubM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    2
    Thanks you Sorry, maybe my English is too weak

    I mean, every time I close the form, the text box becomes empty. I would like to complete them with the data from this table (this table has dates of the last update).
    I've tried to do this before by creating a global variable, but it doesn't work. Like this for example:
    Code:
    Public value_macro_1 As Date
    
    
    Public Sub Form_Close()
    value_macro_1 = text_field_1
    End Sub
    
    
    Public Sub Form_Open(Cancel As Integer)
    text_field_1 = value_macro_1
    End Sub
    I don't know what to do to, but I think that my problem is quite easy to resolve by an expert

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    14,908
    Sorry JakubM I still do not understand.

    I would like to complete them with the data from this table (this table has dates of the last update).

    Perhaps you could write a description with details in your native language, then use Google translate to go from
    your language to English, and post the English.

    The "macro" you are showing is vba code.

    I did find this code to use a value from previous record in a new record via Google.

    Code:
    Private Sub Form_Current
    ' set the default value of the textbox to the textbox's current value
    'this puts the current value for use with a new record
        
        If Not Me.NewRecord = True Then
            Me!YourTextBox.DefaultValue = Me!YourTextBox.Value
        End If
    
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 08-06-2016, 10:39 AM
  2. Replies: 12
    Last Post: 12-31-2014, 09:30 AM
  3. Replies: 1
    Last Post: 09-27-2013, 04:07 PM
  4. Replies: 7
    Last Post: 10-17-2012, 11:59 AM
  5. Replies: 4
    Last Post: 08-17-2011, 05:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums