Results 1 to 8 of 8
  1. #1
    JMac is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    21

    VBA code: copy 1 field to another in a different table...

    Morning all
    I have the following code which works well on a command click on a form for running a query, closing the current open form and opening another.
    What I want to squeeze in, is to copy the number which has been updated by the query and use that as a new record in the newly opened table... any thoughts.... thanks...

    Private Sub Command36_Click()
    On Error GoTo Err_Query_update_for_part_number_Click

    Dim stDocName As String

    stDocName = "Part number generation update"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

    Exit_Query_update_for_part_number_Click:


    DoCmd.Close acForm, Me.Name


    DoCmd.OpenForm "Cat data entry"


    Exit Sub
    Err_Query_update_for_part_number_Click:
    MsgBox Err.Description


    Resume Exit_Query_update_for_part_number_Click
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    One way to pass the value to opening form is with OpenArgs argument. What I don't see in your code is how the part number is generated. How can it be available to the code?

    DoCmd.OpenForm "Cat data entry", , , , , , partnumberhere
    DoCmd.Close acForm, Me.Name

    Then in the Open event of the form, extract the value from the OpenArgs

    If IsNull(somefield) Then somefield = Me.OpenArgs
    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
    JMac is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    21

    re:

    Hi June7
    The part number is a simple update query, just collating a couple of fields together.. fieild 1 + field 2 + uniqueID = Part number (all in the first 'part number' table via a form)

    I guess the step I need is part of your observation of how the part number is available to the code..

    Currently its updated and resides in the last record in the 'part number' table
    I want this newly generated number to pass across to the new 'cat data entry form' and become the basis of a new record...
    JMac

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If the part number is just two concatenated fields of the currently open form then they are still available for 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.

  5. #5
    JMac is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    21
    Yes, effectively its 3 fields but it doesnt update until I run the query!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Does that matter? The 3 fields are part of the open form and have data then they are available for concatenation in the code.

    Do you want to provide project 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.

  7. #7
    JMac is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    21
    Well thanks to some embedded pictures the file is currently residing at 20Mb! Maybe Ill PM you with the intricate details, I may try to delete the pics too!!

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If still too big, can upload to fileshare site such as box.com and post link to the file.
    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: 14
    Last Post: 03-01-2012, 02:39 PM
  2. Replies: 5
    Last Post: 02-21-2012, 07:33 AM
  3. Code to copy data from one field to another?
    By graffiti in forum Programming
    Replies: 1
    Last Post: 12-01-2011, 11:13 AM
  4. String to Copy a Field of Data to Another Table
    By aquarius in forum Programming
    Replies: 1
    Last Post: 09-17-2010, 09:02 AM
  5. Copy form field to another table
    By Dega in forum Forms
    Replies: 6
    Last Post: 05-21-2010, 02:57 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