Full Version: PopUp form does not stop for data entry
UtterAccess Forums > Microsoft® Access > Access Forms
donaldmaloney
I have a form and click on a button to open a popup form.
I want to enter data nad then test the data.
I have two buttons OK and Cancel
so the form looks like an input box BUt the form allows on click for the buttons.
Code is :
Private Sub Command13_Click()
On Error GoTo Err_Command13_Click
Dim stDocName As String
Dim stLinkCriteria As String
frminputBoxKey = 0
Forms!frmwater.txtflow.Value = ""
DoCmd.OpenForm "frminputBox", , , , , acHidden
'Stop
Forms!frminputBox.Caption = "HEaderCaption"
Forms!frminputBox.Label1.Caption = "Question in form"
Forms!frminputBox.Text1 = ""
DoCmd.Close , "frminputBox"
'Stop
DoCmd.OpenForm "frminputBox", , , stLinkCriteria, , acDialog
CODE DOES NOT STOP HERE FOR DATA FROM THE FORM BUT GOE SON WITH NEXT INSTRUCTION
etc.
HOWEVER code does NOT wait for input from form but just goes on as if form was never opened
I even had DoCmd.Close , "frminputBox" after the second openform command but the form is still displayed.
How do I stop the code so I can get the input from the popup form? before the code under the original callform button completes?
THe form stays open until the code under the original callform button is completed
in frminputbox I have
Private Sub cmdOK_Click()
'Stop
frminputBoxKey = 1
retVal = Text1
DoCmd.Close acForm, "frmInputBox"
End Sub
Private Sub cmdCancel_Click()
frminputBoxKey = 0
retVal = ""
DoCmd.Close acForm, "frmInputBox"
End Sub
Don
Jack Cowley
Try putting :
oCmd.OpenForm "frminputBox", , , , , acDialog
HAs the first line of your code and then the code that follows just to see if the form pops up and stay open until you close it. You do not need the Dim statements in our code and I am not sure why you are opening and closing the popup before you open it with the code above.
Jack
donaldmaloney
Jack,
Thanks for your quick reply.
Odid that and it keepson going.
The reason for opening hidden was to create a "template" for an Inbox clone form but with the ability to know what button was clicked.
So I open hidded, change the info on the form, close the hidden form then open with acdialog.
but the code after the form executes while the form is open.
wierd. I even tried running a loop until input is made but I just get the hourglass and the form never reall displays right.
Then I have to hit break to stop the loop.
any other ideas?
Don
Jack Cowley
Instead of using a 'template' you can use code in the forms On Open event to set captions, etc. based on the form opening the popup. Since your code does not seem to be working then it is back to square one. Compact and repair the db. Try importing everything into a new, blank db. If it still fails the create a new, really simple form and save it. Then create a new form with a command button to open the newly created form and see if it works. It may be faster to do that to begin with as something may be corrupt and creating a new form(s) might solve the problem.
th,
Jack
donaldmaloney
Jack,
Have attached a simple form.
code just falls through and doesn't wait for input on the popup form.
Don
Jack Cowley
Don -
If I get rid of all the code in the On Click event of the button on form frmWater (the code before the OpenForm method) and remark out some of the code in the Close and Cancel button on the popup everything works. The error from the Cancel and Close button on the popup has to do with this code:
Private Sub cmdOK_Click()
'Stop
frminputBoxKey = 1
retVal = Text1
DoCmd.Close acForm, "frmInputBox"
End Sub
Private Sub cmdCancel_Click()
frminputBoxKey = 0
retVal = ""
DoCmd.Close acForm, "frmInputBox"
End Sub
And the error is that frmInputBoxKey is not defined (you haven't created a variable named frminputKey). Remark out all the code before the "DoCmd.OpenForm "frminputBox", , , , , acDialog" in the On Click event of the Open Form command button on your form "frmwater" and see if that doesn't fix the problem.
If that works then we can go from there...
Jack
donaldmaloney
Jack,
Deleted the code.
frminputBoxKey was in a module as a global variable.
put it back in.
The popup form was in a module at one time and I used the global variable to tell the code if the OK or cancel button was clicked.
New zip file attached
Don
donaldmaloney
Hmm no attachment here it is
Aquadevel
Don?
Just what are you trying to end up with in the database?
Does a user enter the flowmeter value, or is it from an actual flowmeter?
I've spent 25+ years in SCADA systems, just wondering what you want in the long run.
Aqua
donaldmaloney
Aqua,
The actul use of the data is not important
was looking for a way to emulate a MS acess inputBox by using a form.
Got the initial problem from someone else who wanted a way to input a number and populate a form.
Using MS access input box I can input a number and click OK or Cancel.
OK closes the form and sets the value as Value = inputbox(prompt, title,default,etc)
Cancel sets the value as "".
If no entry and the user enters OK the value is also returned as "".
What I wanted is a way to emulate the input box and know which button was clicked.
The actual use of the number is not important.
What i need to know is how to stop the code from executing when the popup form displays and allow the user to enter a number and click a key.
The code after the popup docmd.openform should only run after the user clicks a button OK/Cancel on th eform.
The issue is how to have the code wait for the form to close.
Don
Jack Cowley
Don -
I am unclear as to what you want to do if the Cancel button is clicked on the popup form, but here is the demo that will put the value selected in the input box into the control on the form that opens the popup. Take a look at the attached and let me know what you want to do with if the Cancel button is clicked. Also, always add 'Option Explicit' to the declarations in the Module, which I have already done.
Jack
donaldmaloney
Jack,
What I was looking to do is capture the "frminputBoxKey = 1" for the OK button, later would activate the "frminputBoxKey = 0" for the cancel button.
This way, in the code, I would know what button was clicked.
So if someone entered no info and clicked OK it would just reopen the form and if I wanted to I could add another message to the pop up form.
ran your code and the form poped up OK,
But when I had the form pop up with the module e.g.
On Error GoTo Err_Command13_Click
Forms!frmWater.txtFlow = Inputbox2("enter flow value", "FLOW VALUE", "")
the pop up showed but the code following the above line executed without waiting for the data to be entered or the OK/Cancel button to be clicked.
Any idea why that happened?
The module code is :
Option Compare Database
Option Explicit
Public frminputBoxKey As Integer
Public stLinkCriteria As String
Public Function Inputbox2(prompt As String, Optional title As String = "", Optional default As String = "")
frminputBoxKey = 0
DoCmd.OpenForm "frminputBox", , , , , acHidden '<----- opens form hidden
'Stop
Forms!frminputBox.Caption = title
Forms!frminputBox.Label1.Caption = prompt '<-------puts headings etc on form
Forms!frminputBox.Text1 = default
DoCmd.Close , "frminputBox", acSaveYes '<----- closes form
DoCmd.OpenForm "frminputBox", , , , , acDialog '<------Opens form for input BUT code does NOT stop for input???
'Question is why does code not stop executing here???????
'Stop
End Function
Don
Jack Cowley
You say, "So if someone entered no info and clicked OK it would just reopen the form and if I wanted to I could add another message to the pop up form." Do this validation check in the popup Forms Before Update event. In other words do not let them close the popup until they have entered something, otherwise the train has left the station and you are too late.... In the popup Forms Before Update event:
!--c1-->
CODE
If Len(Me.Text1 & vbNullString) = 0 Then
MsgBox "You must make an entry"
Cancel = True
End If

HAs for your Caption, etc. in the popup form - Put the code in the On Load event of the popup form and forget all the open and closing of the popup form:
CODE
Me.Caption = "My Input Form"
Me.Label1 = "Enter Number Here"

The only code you should need in the Open Form button is:
CODE
DoCmd.OpenForm "frminputBox", , , , , acDialog
If MsgBox("Have you received a Schedule B?", vbYesNo) = vbYes Then
    ChkScheduleB.Value = True
    Else
    ChkScheduleB.Value = False
End If

I think you are making this much more difficult than necessary unless I am missing something. If I am missing something the please explain, in simple terms, what it is you need to do.
Jack
donaldmaloney
Jack,
know I can do all of your suggestions and they are good ones.
The issue that is bothering me, to focus on one problem is the one that "'Question is why does code not stop executing here???????" in my prev posts.
From what I read the command "DoCmd.OpenForm "frminputBox", , , , , acDialog"
should pause execution of code until the form is closed.
In the attachment you sent it did.
When I have the code execute in a module or execute with the open hidden,close, open acdialog, it didn't suspend the execution of code
WHy doesn't it?? That's the issue that is bugging me.
Don
Jack Cowley
Don
do not know the answer for a fact, but my guess would be that since the form is being opened 'hidden' that the code will not pause. If you open the form straight away (without opening and closing it) then the code does pause, as it should. In the attachment I sent I eliminated all the code that you had that opened the form hidden, etc. and that cured the problem and I assume that since the form was opened 'hidden', closed, then 'opened' again that the acDialog had no effect.
When you say, "...have the code execute in a module..." do you mean in a Standard module or in the code behind the form? The code you sent was in a form module and I do not recall a standard module, but I did not look there.
If this does not answer your question, it is my best guess, then you may want to post the question in a new thread and maybe on of the other members knows the exact answer. All I can say is that we know it does not work so then another approach needs to be used...
Good luck with this and if you have more questions please let me know and I will do my best to assist you!
Jack
donaldmaloney
Jack,
Thanks for your assistance.
This is strange.
YOur attachment used the ope,,, acdialog and worked.
when I tried the ope,,,hidden, close , open,,,,acdialog it didn't stop.
I think i'm gonna do some more research.
Will get back.
Thanks again
Don
donaldmaloney
Jack,
This is really strange
the code DoCmd.Closeform , "frmInputBox"
I did not close the form
but
DoCmd.Close acForm, "frmInputBox"
did.
Also added:
Do Until Form_frmInputBox.Visible = False
DoEvents
Loop
and the form stays open till the ok or cancel button closes the form.
Now works.
Strange huh?
Don
Jack Cowley
Don -
Closeform' is not a valid method but 'Close, acForm' is.
I'm glad to hear that you have your code working!
Jack
donaldmaloney
Jack, yep me too. kind of surprised that i did't get an error on the closeform.
Thanks for your asistance it was very helpful.
Don
Jack Cowley
Don -
You are very welcome!
Jack
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.