create a new worksheet using a button and open the one generated when second click

STE_IAP
STE_IAP used Ask the Experts™
on
I've written a procedure creating a new worksheet using a
command button. Question is how shall i write the code so that when i click the command button again, it can open the previous generated worksheet but not another new one?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Depending on your code requirements. you could declare a boolean flag to determine if you've already created a new worksheet, and if so, then open .


Dim blnIsCreatedAlready as boolean


form_load()
blnIsCreatedAlready = 0
'other code blah blah
'more code
end sub


command_click()
 if blnIsCreatedAlready = 0 then
     'create your sheet
     blnIsCreatedAlready = 1
 else
     'open your sheet
     blnIsCreatedAlready = 0
 end if
end sub()

Author

Commented:
Thank you xmetrix, but my problem is still there.Maybe i didn't make myself clear.The fact is i generate a series of command buttons according to the user-input number. And each button is able to creat a  correspondent worksheet. e.g.button1 creats worksheet1, and button2 creats worksheet2.The problem is how to make it possible that when i click the command buttons out of order, they can still work properly.(for example,i click button3 after clicked button1 can create worksheet3 but not worksheet2.) Of course another demand is once the correspondent worksheet has been created, button will open the worksheet but not create a new one. Please take into consideration that all buttons are assigned to share a macro. Thanks again.

Author

Commented:
xmetrix, my problem is solved. Actually i just need to rename the buttons so that i can trace them. Anyway, thanks.

Commented:
no problem, sorry about the lack of a second response. i was unable to re-check your status.. anyhow. your welcome

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial