How to use button to Insert Record and dont use press F3

mootoonmootoon Member Posts: 47
I want to know how to use button to insert new record.
plz tell me how to.
AAA

Comments

  • mootoonmootoon Member Posts: 47
    Normally we press F3 to Insert New Record.IF We dont use F3 and want to
    create button to Insert New Record.How to do that ? Any body can do?
    AAA
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    You can use windows scripting for this to simulate F3.

    Just search this forum for examples.
  • sblotsblot Member Posts: 21
    You can do this whith a temporay table in the form like the tracking entries.
  • ShenpenShenpen Member Posts: 386
    f.e. on a Customer form:
    Customer.INSERT(TRUE);
    GET(Customer."No.");  // position form to the empty record.
    

    Do It Yourself is they key. Standard code might work - your code surely works.
  • krikikriki Member, Moderator Posts: 9,118
    Shenpen wrote:
    f.e. on a Customer form:
    Customer.INSERT(TRUE);
    GET(Customer."No.");  // position form to the empty record.
    
    More exactly would be to put this code in the button:
    CLEAR(rec);
    INSERT(TRUE);
    FIND('=');
    
    And I think the FIND is not even necessary.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • WaldoWaldo Member Posts: 3,412
    Didn't test it, but don't you have to do an INIT (clear all values) instead of a CLEAR(Rec)?

    Personally, I use the "Mark Brummel"-way ... simulate "F3" with the sendkeys...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I usualy do things the "Mark Brummel" way to :mrgreen:
  • WaldoWaldo Member Posts: 3,412
    =D>

    After your answer, I couldn't call it the waldo-way anymore :wink:

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • krikikriki Member, Moderator Posts: 9,118
    Waldo wrote:
    Didn't test it, but don't you have to do an INIT (clear all values) instead of a CLEAR(Rec)?
    No, you also need to clear the primary key. INIT clears all except the fields of the primary key. And the INSERT(TRUE) triggers the code to generate a new primary key.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • WaldoWaldo Member Posts: 3,412
    Indeed, you're right ... .

    I was only thinking of how I do it, and if I create a new record, i do "INIT" and then fill in the primary key fields, so I don't have that issue. In this case, it's necessary indeed to clear the PK as well ...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • DenSterDenSter Member Posts: 8,307
    So then you'd nee to do
    CLEAR(Rec);
    Rec.INIT;
    
    So you have a new record and all init values are taken care of as well.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    OR
    INIT;
    "No." := '';
    

    This way the filters the user has set remain, just like using F3.
  • SchwarzSchwarz Member Posts: 8
    Hello,

    i tried the following on the Customer Card:

    New Menu Button with one Menu Item "Test" and Shortcut F3.
    New Command Button named "New" with this code in the OnPush Trigger:


    Clear(rec);
    init();
    Insert(True);

    I put the CommandButton over the Menu Button so the User cant see the Menu Button.

    After running the Form nothing happend on hitting F3, because the Shortcut on the Menu Item overwrites the existing Shortcut F3.

    I there is a No. Series for the Customer you will receive a new Record after clicking the "New" Button. Otherwise you have to fill in the PK -Fields directly in the OnPush Trigger.
  • DenSterDenSter Member Posts: 8,307
    I don't understand why you would create a button that does the same thing as F3, give it the shortcut F3 and it would do the same.... Couldn't you just better leave the whole thing alone? That way, when you hit F3, it will act as though you hit F3, because you just hit F3 :shock: go figure...
  • mrQQmrQQ Member Posts: 239
    my guess is simply cause he doesn't want to allow inserts on form, or wants to disable fields etc.. lots of possible reasons

    i once tried it, but wasnt able to make it work
  • SchwarzSchwarz Member Posts: 8
    Hello,

    its only an idea for solving mootoon's problem.

    Normally we press F3 to Insert New Record. If We dont use F3 and want to
    create button to Insert New Record.How to do that ? Any body can do?



    I dont think that it is a good idea not to use the Navision functionality for this think, but maybe there are some special reasons :D

    By the way,

    the menu button dosnt do the same as F3!! It prevents the user for using "normal" F3! To Insert a new record you have to push the Command Button with your own code.

    Regards,
    Frank
  • DenSterDenSter Member Posts: 8,307
    I was trying to be sarcastic in my last post :shock: sorry if that didn't come through. Of course people have reasons to do things, and to them they are perfectly valid. Just ask my wife, she'll tell you I am weird, when I think everything I do makes perfect sense :D
Sign In or Register to comment.