Results 1 to 4 of 4
  1. #1
    joecamel9166 is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    85

    Saving unbound textbox data

    I have created an unbound textbox that uses the following code to create a new ID# for each record.

    Private Sub Form_Current()


    If Me.NewRecord Then




    Me.txtUnitID = 1 + DMax("Unit", "tblUnits")
    End If
    End Sub

    The problem I am having with this is that the number that this generates doesn't save into the record.
    So I can fill this form out and have 20 new entries, but the "Unit" field is left blank (unless I enter it manually into the table).

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Unbound fields have to be specifically saved or you can fake it.

    I'm assuming you're doing this because you want sequential numbers on your table tblUnits with no breaks (i.e. if you use autonumber and cancel a record you'd have gaps in your numbering). If this is your goal you just need to change your txtunitid field to a bound field on your table. Just be aware you may get some errors if you don't correctly handle null values, for instance if the only required field on your table is the UNIT field leaving your form on an otherwise blank record would cause a record to be created in your tblUnits table with a UNIT field and everything else blank.

  3. #3
    joecamel9166 is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    85
    Thanks. If I delete a record, I want it to still show, but as deleted. Do you have any suggestions on how to specifically save the unbound field?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    rpeare suggested
    Quote Originally Posted by rpeare View Post
    ...<snip> you just need to change your txtunitid field to a bound field on your table. </snip>.....
    Open your form, set the control source for the control "txtunitid" to the field that holds the ID# for each record. (this makes the control "Bound")

    But I would use the "Form_BeforeUpdate" event, instead of the "Form_Current" event.
    Code:
    Private Form_BeforeUpdate(Cancel As Integer)
      If Me.NewRecord Then
        Me.txtUnitID = 1 + DMax("Unit", "tblUnits")
      End If
    End Sub

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

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2015, 01:24 PM
  2. unbound textbox to bound textbox
    By thescottsman92 in forum Access
    Replies: 3
    Last Post: 08-29-2013, 02:02 AM
  3. Saving unbound feild values
    By John Saul in forum Access
    Replies: 1
    Last Post: 06-19-2013, 06:22 AM
  4. Replies: 8
    Last Post: 04-12-2013, 08:59 PM
  5. Saving bound and unbound fields
    By mejia.j88 in forum Forms
    Replies: 2
    Last Post: 11-04-2011, 05:09 PM

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