Results 1 to 10 of 10
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    What is wrong with this code?

    In the Excel sheet that I have attached when I press the button to Change Select Text to Numbers, I get


    the error shown in capture the graphic.

    The dialogue box that opens when I try to assign the macro changetextonumber()

    Shows that macro very differently. It is a very long line of letters and words

    How to fix this?

    R,

    Lou Reed
    Attached Files Attached Files

  2. #2
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Ignore this. I have the answer. I think.

    R,

    Lou Reed

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I use this code:

    Code:
    Dim c As Range
    For Each c In Selection
        c = c.Value
    Next c
    And had to reassign the macro to the button.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Here you are. For some reason the macro was incorrectly assigned to the button, so I reassigned it and the error went away.

    I also amended the two change macros a bit. The (misspelled) macro chnagetexttonumber didn't work at all, so I fixed the spelling and rewrote it (almost the same as changenumbertotext), and I amended both of them to make changes to cells only if a) the cell was not blank AND b) the value in it was numeric, using the len() and isnumeric() functions. That way it doesn't bother with cells which are already non-numeric text.

    The very useful isnumeric() function works whether the value you give it is a number or a character string that looks like a number, so isnumeric(23) and isnumeric("23") both evaluate to True.
    Attached Files Attached Files

  5. #5
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    First how can you tell that a macro is not correctly assigned? I just write the macro compile it, rewrite code if errors are present, and then recompile.

    Then I put a form control or button on the Excel sheet, when finished, it asks me to assign a macro. I do.

    If is wrong the only way I know is to check code(repair if needed) and recompile.

    I cannot just get a list of macros an the buttons they are assigned to.

    Also, why did you leave out select cells in your code/example?

    Any help appreciated. Thanks in advance.

    Respectfully,


    Lou Reed

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I uploaded the db that you posted. I also uploaded the Excel. Then I went through the required steps to prepare the Excel file to be imported to Access and impoted it.

    I got an error file as you can see.

    I thought that I select all of the cells apparently I did not.

    How do I get rid of the error file?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Did you notice that all the errors were in the same column - Gate 22? I figured that there must be something different about that column, and there is. There is no data (text or numeric) in any of the cells until Row 51, where there is a "10" - as text (i.e. it has the Apostrophe flag in it). My guess is that when Access is doing the import and deciding what the field types are, it doesn't look as far as Row 51, so it makes the table field a numeric by default.

    A quick fix is to put the word "Text" in Row 2 of that column, and it imports fine, no errors. You can always edit the "Text" out of that row after the import. But there was nothing wrong with the Excel file; it was just the quirky way Access works sometimes.

  8. #8
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, I understand. I did get it to import before with no errors at all.

    I wonder what is causing this to occur only occasionally.

    Respectfully,

    Lou Reed

  9. #9
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I am curious about my command on my Excel spreadsheet to select cells. It works most of the time, then again it fails at times. I have to press the control at least twice to get all of the cells select and I would think once would be enough.

    Also, I noticed in your solution you did not even have such a control, I guess that you must have used cntrl-A. When I do that I must press cntrl-A at least twice. So I am not sure that my "Select Cells" form control
    is any better than just pressing I would be interested in your thoughts on this.

    I have attached my Excel spreadsheet for your examination.

    Any help appreciated. Thank in advance.

    Respectfully,

    Lou Reed

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The latest posted file has:

    Dim Rng As Range
    Set Rng = Range(Cells(1, 1), ActiveCell)
    'Selecting only hardcoded data
    Rng.SpecialCells(xlCellTypeConstants).Select


    Another version of your workbook has this code to select cells:

    ActiveSheet.UsedRange.SpecialCells(xlCellTypeConst ants).Select

    This version works on one click.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. What is wrong with this code
    By MarkA70 in forum Programming
    Replies: 2
    Last Post: 02-13-2016, 06:19 PM
  2. Whats wrong with this code?
    By shabbaranks in forum Programming
    Replies: 2
    Last Post: 03-20-2012, 08:01 AM
  3. What's wrong with my code?
    By Dalagrath in forum Forms
    Replies: 11
    Last Post: 05-18-2011, 04:34 PM
  4. What is wrong with this code?
    By nkenney in forum Forms
    Replies: 2
    Last Post: 11-16-2009, 03:04 PM
  5. Anything wrong with this one line of code?
    By alsoto in forum Reports
    Replies: 3
    Last Post: 07-01-2009, 09:23 AM

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