Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I need a real code expert.. Cause I'm not :)

    I have this code which should append these fields from one table to the other.. The tables do not have identical fields.. Table 1 has 2 added fields called [voucher type] and [Record status].. This code will work if I add these fields to table 2 and the code.. The problem is I don't want to add these fiels to table 2.. I f I run the code as is it gives me an error saying that the 2 added field are not found.. Any thoughts? Thanks..

    Sub AppendVoucher()

    Dim WhereCriteria As String
    Dim AppendTable As String

    AppendTable = Program & "Resolution"
    WhereCriteria = "([Voucher#] Is Not Null Or [Voucher#]<>'')AND ([Date Assigned] Is Not Null) AND ([First Name] Is Not Null Or [First Name]<>'') AND ([Last Name] Is Not Null Or [Last Name]<>'') AND ([Reason] Is Not Null Or [Reason]<>'') AND ([Type] Is Not Null Or [Type]<>'')"

    DoCmd.RunSQL "INSERT INTO " & Program & " SELECT " & AppendTable & ".* FROM " & AppendTable & " WHERE " & WhereCriteria
    [img]/w3timages/icons/spook.gif[/img]<font color=ff9999>text</font color=ff9999>

  2. #2
    Scott A
    Guest

    Re: I need a real code expert.. Cause I'm not :)

    It's because you are selecting all the fields (*) from the table 1.

    You SQL statement looks something like:
    INSERT INTO <Table 2>
    SELECT <Table 1>.*
    FROM <Table 1>
    WHERE ...

    You'll need to change the <Table 1>.* to the actual field list. So, the SQL would look something like:
    INSERT INTO <Table 2>
    SELECT <Field 1>, <Field 2>, ...
    FROM <Table 1>
    WHERE ...

    HTH

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: I need a real code expert.. Cause I'm not :)

    Thanks Scott.. I thought that might be it.. [img]/w3timages/icons/thinks.gif[/img][img]/w3timages/icons/thinks.gif[/img]

Posting Permissions

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