Results 1 to 3 of 3
  1. #1
    Eowyne is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    13

    Runtime error with ActiveCell.offset

    Hi there, Im running the following code:

    Code:
    Function Fill_Fields(xlWS, objXL, MyRec)
    FieldCount = 0
        MyRec.MoveFirst
        xlWS.Range("A2").select
        While Not MyRec.EOF
            For Each fld In MyRec.Fields
                With objXL.ActiveCell
                    .NumberFormat = "@"
                    .Value = UCase(fld.Value)
                    .offset(0, 1).select
                    FieldCount = FieldCount + 1
                End With
            Next fld
            MyRec.MoveNext
            objXL.ActiveCell.offset(1, -FieldCount).select
        Wend
        With xlWS.UsedRange
            .Font.Name = FontFace
            .Columns.AutoFit
            .HorizontalAlignment = 1
            .Borders.LineStyle = 1
        End With
        xlWS.Range("A:A").Columns.Hidden = True
        MyRec.Close
        Set MyRec = Nothing
    End Function
    and I get an error "1004" when my function adresses the ActiveCell.Offset(1, -FieldCount).

    However, I need the -FieldCount (where it obviously crashes upon, since the function works great while useing -6) because the function is for multiple tables and they don't all have the same number of fields.

    I'm Using the offset to reset the pointer to the rule below the first, and then -FieldCount to the left (so it goes from A11 to B1)..

    any ideas on how to fix this?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    what variable type if FieldCount?? does it match the arg types?? I believe they are LONGS for that method.

    have you tried "-(FieldCount)" instead?? I don't know if that would work...

    have you tried resetting the FieldCount first, so you can eliminate the (-) sign?? e.g.-
    Code:
    fieldcount = fieldcount - (fieldcount * 2)
    activecell.offset(1, fieldcount).select
    and are you sure your OFFSET arguments are in the right order?? rows are first and columns are second, right?? if columns are first, that's your error.

  3. #3
    Eowyne is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    13
    Quote Originally Posted by ajetrumpet View Post
    what variable type if FieldCount?? does it match the arg types?? I believe they are LONGS for that method.

    have you tried "-(FieldCount)" instead?? I don't know if that would work...

    have you tried resetting the FieldCount first, so you can eliminate the (-) sign?? e.g.-
    Code:
    fieldcount = fieldcount - (fieldcount * 2)
    activecell.offset(1, fieldcount).select
    and are you sure your OFFSET arguments are in the right order?? rows are first and columns are second, right?? if columns are first, that's your error.
    it's indeed rows first, columns second.

    You were right about the variable type of FieldCount,
    It has to be 'Long' for it to work.


    Thanks about that!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Runtime Error 3021
    By paddon in forum Programming
    Replies: 12
    Last Post: 03-14-2011, 12:14 PM
  2. Error in Runtime Only
    By drunkinmunki in forum Programming
    Replies: 7
    Last Post: 12-16-2010, 03:43 PM
  3. runtime error 3219
    By Rider570 in forum Programming
    Replies: 3
    Last Post: 07-07-2010, 09:12 PM
  4. Help With Runtime Error 4248
    By KLahvic in forum Programming
    Replies: 1
    Last Post: 04-09-2010, 07:47 AM
  5. Runtime 3075 error
    By whm1 in forum Programming
    Replies: 4
    Last Post: 03-24-2010, 02:50 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