Results 1 to 10 of 10
  1. #1
    Drak is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    22

    Transferring data from one table, to another.

    Hello. I tried searching the forums for an answer and I found similar issues, but I still can't quite get it. Attached is my current example database (It's small).


    I have a form that allows you to lookup / change / add customers.

    On this form, I have a button "New Repair" that opens another form (New Repair) where I enter the name, and the status of the repair.

    My issue is how do I send the CID (the company id in the table) from the one form (Customer List), to the second one (New Repair). Then with the CID, I would like todo a query to the customer database and retrieve the company name based on the CID, and display it in the header.

    I have the tables laid out with an example customer.
    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,631
    Basing CID primary key on first six letters of name can cause issue. Eventually, likely will encounter two names that start same. Suggest design a different unique ID scheme or use Autonumber datatype.

    Instead of opening New Repair from Customers form, set up so open New Repair form directly and select company in combobox on that form. Include the Customers table in the record source by joining on CID fields. This way the related customer info will be available for display in textboxes. Lock those textboxes so values cannot be edited on this form.

    Or, put the New Repair form as a subform on Customer List form. Maybe use a tab control to organize the controls. Customer info on one tab, New Repair subform on another tab.

    Anything else will involve VBA 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.

  3. #3
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481
    I have access 2007 and can't open your db. Ive done essentially what you want to do as follows.
    When the button is clicked, the buttons on click event runs a VBA procedure or a macro which opens the second form and makes the first form invisible. The second forms on open event can look at the form 1 value and insert it into a filter. You'll need to do a requery.
    If you don't need to return to the 1st form, the on click macro/procedure could store the value in a global variable.
    This would not require a reference to the first form, so it could be closed after the on click event.
    Tell me what needs more detail.

  4. #4
    Drak is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    22
    How would I go about doing it in VBA? Use the "onclick" procedure, then just run a query asking the table for a company based on the id?

  5. #5
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481
    The 'on click' procedure would, at a minimum, open the 2nd form. If the first form is no longer needed, then the I'd would need to be assigned to a global variable before opening the 2nd form. After issuing 'open form', the 1st form could close.
    The 2nd form would be based on a query without criteria for Id. The form filter would reference the global variable, Id, or reference form1's control value for the id. You need to check the form properties to be sure that the filter is applied.
    You can also generate a filter during the 2nd forms 'onopen' event, but doing so will require a 'requery'.
    My Access PC isn't available today. I apologize for not being able to generate a working example.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,631
    Several ways to do this. You can have code in the click event of main form or in the Open event of New Repair.

    In click event after line to open form, set value of the field on New Repair:
    Forms![New Repair]!CID = Me.CID

    Or use the OpenArgs argument of DoCmd.OpenForm
    DoCmd.OpenForm "[New Repair]", , , , acAddNew , , Me.CID
    Then in Open event
    If Not IsNull(Me.OpenArgs) Then Me.CID = Me.OpenArgs

    I just thought of another way that does not require VBA but I have never applied it. You can set Default value property of the CID field on New Repair form to the field on main form. If the field is null when record is opened, the default will apply, since a new record would be null, this might work for you. The Default parameter would be: Forms!formname!CID.
    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
    Drak is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    22
    Quote Originally Posted by June7 View Post
    Several ways to do this. You can have code in the click event of main form or in the Open event of New Repair.

    In click event after line to open form, set value of the field on New Repair:
    Forms![New Repair]!CID = Me.CID

    Or use the OpenArgs argument of DoCmd.OpenForm
    DoCmd.OpenForm "[New Repair]", , , , acAddNew , , Me.CID
    Then in Open event
    If Not IsNull(Me.OpenArgs) Then Me.CID = Me.OpenArgs

    I just thought of another way that does not require VBA but I have never applied it. You can set Default value property of the CID field on New Repair form to the field on main form. If the field is null when record is opened, the default will apply, since a new record would be null, this might work for you. The Default parameter would be: Forms!formname!CID.
    Thanks for the info. Once I got the CID value on the new repair form, how do I grab the company name that relates to the saved CID, in the table, and show it on the new repairs form?

    Sorry for the newbie question. Thanks again.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,631
    One way is to simply include the company table in the form's recordsource by joining the two tables. The jointype would be like 'show all records from repair table and only those from customers that match'. This is a left or right join (I always forget which) but not an inner join. This will make the related customer information available for display in textboxes. Set these textboxes as Locked Yes TabStop No so cannot be edited on this form.

    Another way to show related records is form/subform arrangement. Main form bound to customers and subform bound to repairs.
    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
    Drak is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    22
    I linked the two tables toghter, and using DLookUp:
    Code:
    Private Sub Form_Load()
        Dim Company As Variant
        Company = DLookup("[Company]", "Customers", "[CID] =" & Me.CID)
        TitleTest = Company
    End Sub
    Which "seems" to work but VB throws this error at me:
    "The expression you entered as a query parameter produced this error: 'ABM'"

    "ABM" is the correct CID I'm trying to pull it's Company Name from the "Customers" table.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,631
    There is no reason to use the DLookup when tables are joined in the form's RecordSource. Also, the DLookup could be in textbox ControlSource. No need for VBA.
    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. Transferring data to a second form
    By JayX in forum Access
    Replies: 2
    Last Post: 12-15-2011, 11:31 AM
  2. transferring data from word to access
    By RickScolaro in forum Access
    Replies: 6
    Last Post: 09-08-2011, 05:17 PM
  3. Replies: 1
    Last Post: 09-07-2011, 02:45 AM
  4. hyperlink data not transferring to destination table
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 09-17-2010, 06:12 PM
  5. Transferring data from table to table.
    By jlm722 in forum Import/Export Data
    Replies: 6
    Last Post: 09-30-2009, 06:16 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