Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    rochy81 is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2008
    Posts
    22
    Hi, Sorry to bother you again. I'm not sure if you remember me or not but I was the one who asked you for help on a script to normalize an excel spreadsheet to an access database. I want to add another field to that table using that script you wrote for me called "Number". I tried to modify it but I don't understand the script.



    I thought I could just add OutRS.Fields(3) = .Fields(FieldIX).Value
    or change the FieldIX to equal 3 or both but that did not work.

    Can you help me out once more?

    Thank you for your help again!

    For FieldIX = 2 To .Fields.Count - 1
    If Len(.Fields(FieldIX) & "") > 0 Then
    OutRS.AddNew
    OutRS.Fields(1) = .Fields(1)
    OutRS.Fields(2) = .Fields(FieldIX).Name
    OutRS.Fields(3) = .Fields(FieldIX).Value
    OutRS.Update

  2. #17
    rochy81 is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2008
    Posts
    22
    I played with the script again and it looks like the script below.

    It's strange but all of the values are matching up correctly but it's not under the correct field. For example, part numbers would appear under quantity.

    Set InRS = db.OpenRecordset("XLsheetTest", dbOpenDynaset)
    Set OutRS = db.OpenRecordset("Test", dbOpenDynaset)
    With InRS
    Do While Not .EOF
    For FieldIX = 3 To .Fields.Count - 1
    If Len(.Fields(FieldIX) & "") > 0 Then
    OutRS.AddNew
    OutRS.Fields(1) = .Fields(1)
    OutRS.Fields(2) = .Fields(2)
    OutRS.Fields(3) = .Fields(FieldIX).Name
    OutRS.Fields(4) = .Fields(FieldIX).Value
    OutRS.Update
    End If
    Next FieldIX
    .MoveNext
    Loop

  3. #18
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    The destination table would need an additional field added first. The .Fields(index) is zero based so .Fields(4) is actually the 5th field. What value from the source were you planning to put in this new field? You were not thinking of naming the field Number were you because that is a reserved word in Access.

  4. #19
    rochy81 is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2008
    Posts
    22
    Oops, yeah, I was using Number as a field. I'll Change it to Order. It's a simple integer. That field would be the 2nd field in the excel file. It would be the 3rd when it's been imported into access though because the AutoId field is added which is first.

    So it should look like
    ID
    Date
    Order
    Part
    Quantity

    After I ran the script it actually came out as
    ID
    Date
    Quantity
    Order
    Part

    I attached a test Excel sheet. Please look at Sheet2.

    Thanks again!

  5. #20
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    So you need something like this attachment?

  6. #21
    rochy81 is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2008
    Posts
    22
    Yeah, oh that's weird. I modified the script that way too but my fields came out jumbled.

    Thanks!

    also what is that ModGetOpenFile script?

  7. #22
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I used the design view of the table to arrange the fields. ModGetOpenFile is another issue I was working on for a poster and using your db to do some stuff. Sorry, just ignore it.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 03-29-2009, 07:20 AM
  2. help with database creation
    By terrep263 in forum Database Design
    Replies: 1
    Last Post: 08-30-2006, 07:59 AM
  3. Will Pay $$$ for help w/ database creation!
    By eyesbryte in forum Access
    Replies: 1
    Last Post: 07-03-2006, 01:56 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