Results 1 to 13 of 13
  1. #1
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155

    Code for New rec

    Private Sub MoveToMain()
    Me.Parent.FNAME = NAME
    Me.Parent.LNAME = LNAME
    Me.Parent.ADD = ADD
    Me.Parent.[ADD 1] = [ADD 1]


    Me.Parent.[ADD 2] = [ADD 2]
    Me.Parent.PLACE = PLACE
    Me.Parent.PIN = PIN
    Me.Parent.DISTRICT = DISTRICT
    Me.Parent.STATE = STATE
    End Sub

    I have written the above code to transfer fields from subform to main form. This transfer takes place when I click a field on the subform. But I want to ensure that the transfer is to a new record on the main form. It should not overwrite old records on the main form. How to achieve it?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use GoToRecord to move the main form to a new record first.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by pbaldy View Post
    You can use GoToRecord to move the main form to a new record first.
    Should it be,

    RunCommand acCmdGoToRecord
    Me.Parent.[ADD 1] = [ADD 1]
    Me.Parent.[ADD 2] = [ADD 2]
    Me.Parent.PLACE = PLACE
    Me.Parent.PIN = PIN
    Me.Parent.DISTRICT = DISTRICT
    Me.Parent.STATE = STATE
    End Sub

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Consider:

    DoCmd.GoToRecord acDataForm, Me.Parent, acNewRecord

    Why are you duplicating data between main and sub forms?
    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
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by June7 View Post
    Consider:

    DoCmd.GoToRecord acDataForm, Me.Parent, acNewRecord

    Why are you duplicating data between main and sub forms?

    I am not duplicating data. My subform contains addresses already present. If a new record on the main form requires the same address then I need not type it, I will just click on the subform.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    If you are saving the same address info from one record to another record then that is repetitive data. And if the main form and subform are bound to different tables, that is duplicating between tables as well. If you want to provide db for analysis, follow instructions at bottom of my post.

    Do you have a table of Addresses? Just save AddressID to data table.
    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
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by June7 View Post
    If you are saving the same address info from one record to another record then that is repetitive data. And if the main form and subform are bound to different tables, that is duplicating between tables as well. If you want to provide db for analysis, follow instructions at bottom of my post.

    Do you have a table of Addresses? Just save AddressID to data table.

    Thanks for the advice. GOD BLESS YOU!!! Where can I find tips for designing Accesss Aplications?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    There are introductory tutorials all over the web. Do a search. Or buy a cheap, used book.
    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.

  9. #9
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by June7 View Post
    There are introductory tutorials all over the web. Do a search. Or buy a cheap, used book.


    DoCmd.GoToRecord acDataForm, Me.Parent, acNewRecord

    This command is giving variable not defined error for acNewRecord

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Sorry, should be acNewRec. Intellisense popup tips should show you that as you type the code.
    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.

  11. #11
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by June7 View Post
    Sorry, should be acNewRec. Intellisense popup tips should show you that as you type the code.

    I typed the following command:

    DoCmd.GoToRecord acDataForm, Me.Parent, acNewRec


    I am getting the following error:

    Runtime error ‘2498’:
    An expression you entered is the wrong data type for one of the arguments.

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Okay, I finally did a test instead of relying on memory. This worked for me.

    DoCmd.GoToRecord acDataForm, Me.Parent.Name, acNewRec

    or instead of Me.Parent.Name, simply: "YourFormNameHere"
    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.

  13. #13
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by June7 View Post
    Okay, I finally did a test instead of relying on memory. This worked for me.

    DoCmd.GoToRecord acDataForm, Me.Parent.Name, acNewRec

    or instead of Me.Parent.Name, simply: "YourFormNameHere"

    Thanks a Lot!!! GOD BLESS YOU!!!!!!

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

Similar Threads

  1. Replies: 20
    Last Post: 10-13-2015, 09:05 AM
  2. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  3. Replies: 4
    Last Post: 03-10-2014, 12:18 PM
  4. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  5. Replies: 1
    Last Post: 05-04-2013, 12:19 PM

Tags for this Thread

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