Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005

    Unanswered: Field Name detection

    Hi, I have a problem.

    Suppose I have one Excel file to import in the MS Access, and I will copy the content to another table.

    eg. File 1:
    Unit FileNum Code
    File 2:
    Unit FileNum Code

    rs .....("File 2")
    rstemp.....("File 1")

    In VB, I will write like this:
    rs.Fields("Unit") = rstemp.Fields("Unit").value
    rs.Fields("FileNum") = rstemp.Fields("FileNum").value
    rs.Fields("Code") = rstemp.Fields("Code").value

    After that,
    File 2:
    Unit FileNum Code

    But, if the File 1:
    Unit2 Num Code

    the Field Name is different on next time, then it doesn't work, but the content is same.
    How can I copy the data to File 2 even though the field name is not same,
    of course, we can set
    rs.Fields("Unit") = rstemp.Fields("Unit2").value
    rs.Fields("FileNum") = rstemp.Fields("Num").value
    rs.Fields("Code") = rstemp.Fields("Code").value

    But, can the program detect the column 1, column 2, column3, like that, don't need to use field name, it still can be copied to.
    Like that:
    rs.Fields("Unit") = column1.value
    rs.Fields("FileNum") = column2.value
    rs.Fields("Code") = column2.value
    Does anybody know how to do? Thanks a lot. Thanks.

  2. #2
    Join Date
    Feb 2004
    One Flump in One Place
    The short answer is yes. In fact, it is more efficient to process too. You can call (most) items in a collection by name (as you are) or by index. Try:

    rs.Fields(0) = rstemp.Fields(0).value
    remembering that all Access arrays are 0 based.

    You could even use an iterant (Dim i as integer) and use a loop to do this

    For i = 0 to rs.Fields.Count
    rs.Fields(i) = rstemp.Fields(i).value
    Next i
    pootle flump
    ur codings are working excelent.

Posting Permissions

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