+ Reply to Thread
Results 1 to 9 of 9

ShowDataForm method

  1. #1
    Registered User
    Join Date
    09-24-2006
    Posts
    11

    ShowDataForm method

    I have a simple sheet with cells A6 to N6 defined as headers. These cells are uniformly formated as text with cell borders. All cells below this are for data entry. When I select the first data entry cell (A7) and use the standard Excel menu options Data/Forms, the form appears and works fine. When I try to create a Macro using the same sequence, the macro is created as:
    Please Login or Register  to view this content.
    This does not work and generates the following error:

    Run-Time error '1004':
    ShowDataForm method of worksheet class failed

    Can this method be used in a Macro
    Last edited by VBA Noob; 06-24-2007 at 04:59 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Are you actually calling the code from the data sheet? If not try using the correct sheet, you don't need to select anything.

    Please Login or Register  to view this content.
    Note: according to the Forum Rules you must wrap code in Code Tags
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    09-24-2006
    Posts
    11
    The code is called from a macro button on the correct sheet (it is the only sheet). I do not understand your reference of:
    Worksheets("myData").ShowDataForm

    What does the ("myData") refere to.


    Thanks

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    To make this work in VBA, you have to define a named range called "database".

    Please Login or Register  to view this content.
    HTH

    rylo

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    MyData was just a dummy name to demonstrate. If your code is failing then presumable your activecell is not within the data table. Try adding some code to activate a cell within the table

    Presumably you have some data in the table already.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-24-2006
    Posts
    11
    Rylo

    Your solution works perfectly. I had researched (not enough, I guess) the ShowDataForm method but could not find any reference to the "database" range requirement. I had tried defining a range for the headers but this did not work. Is there an online reference that I can consult to better understand this.

    Many Thanks

    Pierre

  7. #7
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Pierre

    I can't recall where I got that bit of knowledge. Probably a site like this... Having said that, the microsoft website has the following when searching on showdataform

    When you use the ShowDataForm method, Microsoft Excel looks for the data list in two places:

    • The defined name "Database." If a range has been defined as the database, Microsoft Excel will display the data form, and the data in that range will be accessible.

    rylo

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    naming a table of data as "database" helps Excel recognise it as a database, as does making the Header row bold. It isn't strictly necessary and the Database Form should appear once you have two or three lines of daat in the table. What you mustn't have is blank Rows and/or Columns

  9. #9
    Registered User
    Join Date
    09-24-2006
    Posts
    11

    Thumbs up

    Thanks gents....

    Great help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1