How make a button which runs macro only once

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sudhanwa
    New Member
    • Feb 2015
    • 1

    #1

    How make a button which runs macro only once

    Hi
    I have created my own tool in access where by clicking a button the data is inserted into the tool using macros but the problem is if i mistakenly click the button again it will insert the data over the previous one replacing the old data.so i want to make the macro run only once.
    Thanks in advance
  • Brilstern
    New Member
    • Dec 2011
    • 208

    #2
    sudhanwa,

    Your request is a bit misleading. I understand you have created a custom macro to import data into MS Access. If this is a 1 time task why create a button? If this is a repeatable task but you have an issue with accidentally clicking the button add in a verification message in your macro.

    Ex.

    Code:
    Click Macro
    
    vbYesNo
    
    If Yes Then Import Data
    
    If No then end Macro

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3665

      #3
      Also, you could disable the button once you run the macro. This would prevent the user from duplicating the action.

      Comment

      • Brilstern
        New Member
        • Dec 2011
        • 208

        #4
        twinnyfo,

        Question: If op added verbiage such as button.disabled = true on click, this would disable it indefinitely. You would have to go back and create an on open event to set it back to false. This is optional but would not a vbYesNo be more efficient? Not trying to argue, just a question.

        Comment

        • twinnyfo
          Recognized Expert Moderator Specialist
          • Nov 2011
          • 3665

          #5
          Stevan,

          Good question. However, it all depends on how OP has their form set up in the first place. If the Macro is only to be run once per record-view, then they could place code to Enable the button in the OnCurrent Event.

          A combination on using the Enable/Disable features, along with an additional Yes/No field in the data would also prevent duplicate macro events.

          Granted, not much information is provided concerning the structure of OP's DB, Tables and Forms, so we have to make certain presumptions ourselves.

          Bottom line: There are solutions for this problem, but the specifics may require additional detail from OP.

          Comment

          • Brilstern
            New Member
            • Dec 2011
            • 208

            #6
            Thx twinnyfo,

            Never know who might need the explanation.

            Comment

            • twinnyfo
              Recognized Expert Moderator Specialist
              • Nov 2011
              • 3665

              #7
              And....

              Since no new information from OP....

              Comment

              Working...