Results 1 to 8 of 8
  1. #1
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108

    New Record with retaining information

    Hey I was wondering how to code this button so it creates a new record while retaining information such as a serial number. So if you pull up the item check out its past service. then you want to click a "new entry" button but you want the serial number to remain in the field.



    what I got so far is:

    Private Sub BtnAdd_Click()
    On Error GoTo Err_BtnAdd_Click

    DoCmd.GoToRecord , , acNewRec

    Exit_BtnAdd_Click:
    Exit Sub

    Err_BtnAdd_Click:
    MsgBox Err.Description
    Resume Exit_BtnAdd_Click

    End Sub


    but obviously it erases the serial number.

    the field is txtSerialNumber and the control source is SerialNumber.

    Thanks!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,642
    You can set the control's DefaultValue property with the value from record that currently has focus.

    The control is named txtSerialNumber?

    Me.txtSerialNumber.DefaultValue = Me.txtSerialNumber
    DoCmd.GoToRecord , , acNewRec
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Private Sub cmdNewEntry_Click()
    On Error GoTo Err_cmdNewEntry_Click
    Me.txtSerialNumber.DefaultValue = Me.txtSerialNumber
    DoCmd.GoToRecord , , acNewRec

    Exit_cmdNewEntry_Click:
    Exit Sub
    Err_cmdNewEntry_Click:
    MsgBox Err.Description
    Resume Exit_cmdNewEntry_Click

    End Sub



    did that but now it says "you can't go to the specified record"
    Any idea?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,642
    Is SerialNumber field a text type? Try:

    Me.txtSerialNumber.DefaultValue = "'" & Me.txtSerialNumber & "'"

    However, even with the error, should still move to new record row. Set a breakpoint and step debug the code. Does VBA show textbox value? Refer to link at bottom of my post for debugging guidelines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    gpeirce is offline Novice
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Location
    Oregon, USA
    Posts
    13
    I might be talking out of my bee-hind here and if I am, just disregard this. But could you place txtSerialNumber into a global variable on a BeforeUpdate event? You could do that whether or not you need to save the serial number.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,642
    How would setting a global variable populate the field in new record?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    gpeirce is offline Novice
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Location
    Oregon, USA
    Posts
    13
    Sadly, just setting the variable won't put it in the new record. That is where some VBA coding needs to be done.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,642
    Which is what setting the DefaultValue property with VBA should accomplish. I don't know why the code is causing error. The global variable alternative will probably not resolve that. Need to figure out why it is failing now.

    redekopp, If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 04-11-2015, 10:31 AM
  2. Replies: 3
    Last Post: 03-26-2015, 12:18 PM
  3. Replies: 2
    Last Post: 03-13-2013, 06:13 PM
  4. Replies: 1
    Last Post: 04-25-2012, 09:33 AM
  5. Retaining current record.
    By mnsemple83 in forum Forms
    Replies: 10
    Last Post: 08-30-2011, 08:58 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