Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2007
    Posts
    214

    Exclamation Unanswered: Importing data from one form field to another

    I have been trying to solve this dilemma for quite some time. I have two forms in which use tables to house records. I have form "Claims" and form "Charges". Well, certain information from the fields in form "Claims" need to be entered in form "Charges" but only when necessary. Instead of having to retype the same information in form "Charges", is there any way to make a command button that allows me to automatically import this information from "Claims" to "Charges"?

    Example: form claims has the fields below:

    First Name:
    Last Name:
    Employer:
    Account Number:
    State

    form charges has the same exact fields.

    Let's say I am on a certain record in form claims and need that information from the fields above imported into a blank record in form charges. Is there an easy way to do this with a click of a button vs entering all the data again in the other form (charges)?

    Thanks for any insight.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,441
    Provided Answers: 14
    If you want to create a new record in the table that is the recordsource of the form Charges (I'll name this table "Charges" too):
    Code:
    Dim strSQL as String
    
    strSQL = "INSERT INTO [Charges] ([First Name], [Last Name], [Employer], [Account Number], [State]) " & _
        "SELECT [First Name], [Last Name], [Employer], [Account Number], [State] FROM [Claims] " & _
        "WHERE [Claims].[<Primary_Key>] = " & Forms!Claims!Primary_Key
    CurrentDb.Execute strSQL
    Forms!Charges.Requery
    DoCmd.GoToRecord acDataForm, "Charges ", acLast
    You could also:
    Code:
    DoCmd.GoToRecord acDataForm, "Charges", acNewRec
    Forms!Charges![First Name] = Forms!Claims![First Name]
    Forms!Charges![Last Name] = Forms!Claims![Last Name]
    ... etc.
    Keep in mind that the syntax is slightly different when dealing with subforms, if you need to use them.

    By the way, it would be wise to avoid spaces and special characters in the names of the objects as well as stay away form names that are reserved words in Acess, such as Name, Date, etc.
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •