Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I create a customized InputBox?? 3

Status
Not open for further replies.

dirkg

Technical User
May 20, 2000
170
0
0
BE
how can I create a function like InputBox but then with a customized form? In other words I want to open a form from code, make the code wait until the user closes the form and then take the value from a filled in control on that form? <br>If I would use for example a form with a Calendar on it to retrieve a a date frome the user, the line would look like this<br><br> dteDate = CustomDateForm()<br><br>and CustomDateForm would be something like<br><br>Function CustomDateForm() as Date <br><br> docmd.openform (&quot;frmDateForm&quot;)<br><br> =&gt; HERE THE CODE HAS TO WAIT!! HOW?????<br> <br> CustomDateForm = frmDateForm!txtDate =&gt; I have to get the value of the textbox on the form back into the code when the frmDateForm is closed =&gt; HOW???<br><br>end Function<br><br>Thank you very much in advance for your help!<br><br>Greetings,<br><br>Dirk<br><br><A HREF="mailto:dirk.news@yucom.be">dirk.news@yucom.be</A>
 
Hey Dirk:<br><br>I'm still fairly new at this so I may not be seeing the problem correctly.<br><br>However, if the data you are requesting from the user is simple (one element) I think you could use an InputBox function.&nbsp;&nbsp;Check it out in help.<br><br>Hope this helps. <p>Larry De Laruelle<br><a href=mailto:larry1de@yahoo.com>larry1de@yahoo.com</a><br><a href= > </a><br>
 
Hi Larry,<br><br>thanks for your reply. However, I know the InputBox-function and that doesn't help me very much. The data I would like to request from the user are indeed a bit more complicated so that the InputBox-function doesn't help me to solve the problem.<br><br>Greetings,<br><br>Dirk<br><br><A HREF="mailto:dirk.news@yucom.be">dirk.news@yucom.be</A>
 
I'm not sure the steps involved in your situation.<br>But if your form is closed and you need a value from it then put that value in a Global variable.<br>Click On the &quot;modules&quot; TAB and below the Option Explict and any other code put the following.<br><br>Global CurrentDate1 ' This could be any name<br><br>Then close the module and save it. I just leave it as default name &quot;Module1&quot;.<br>Now in your forms Unload event (Note you have to capture the value before you close the form) put this.<br>------------------<br>Private Sub Form_Unload(Cancel As Integer)<br>&nbsp;&nbsp;&nbsp;&nbsp;CurrentDate1 = Me!txtDate<br>End Sub<br>-----------------------------------------<br>So Now you have a variable called &quot;CurrentDate1&quot; that has the date in it and can be used anywhere. It's &quot;Global&quot; to the whole database. Closed form or opened it alway's there.<br><br>OK<br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
It seems that I also have a problem in explaining clearly my own problem ;-)<br>OK, I'll give it another try:<br><br>if you use the function InputBox to retrieve data from the user it happens like this:<br><br>eg.:<br>dim dteDate as String<br>...<br>=&gt; code<br>...<br>&nbsp;&nbsp;&nbsp;&nbsp;dteDate = InputBox (&quot;Please fill out the date:&quot;) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; the Inputbox pops up, and the code waits until the user clicks on the OK-button of the inputbox. Then the date is retrieved from the value the user has typed in the InputBox and the code continues running.<br><br>Now I can indeed asign the value on a form to a global variable but that doesn't help me:<br>I can use the openform-method to open the form but how can I have the code wait until the user has closed the form again????<br><br>Thanks again for your help!<br><br>Greetings,<br><br>Dirk<br><br><A HREF="mailto:dirk.news@yucom.be">dirk.news@yucom.be</A><br><br>
 
Dirk.<br><br>This is fairly easy to do and it involves the difference between loaded forms and visible forms. Assume the form you want to use to get the date is called &quot;GetMyDate&quot;. The control that contains the date is called &quot;Datebox&quot;<br><br>On your calling form, put a command button. Called &quot;Set Date&quot;, maybe. For the button's click event, put:<br><br>Private Sub SetDate_Click()<br>&nbsp;&nbsp;&nbsp;Dim SelectedDate as date<br>&nbsp;&nbsp;&nbsp;DoCmd.OpenForm &quot;GetMyDate&quot;, acNormal, , , , acDialog<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If IsNull(Forms!GetMyDate.Datebox) Then Exit Sub<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SelectedDate=Forms!GetMyDate!Datebox<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Close acForm, &quot;GetMyDate&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' Do whatever you need to do with SelectedDate here<br>End Sub<br><br><br>Now on your form &quot;GetMyDate&quot;, inactivate the close box so the user can only close the form by clicking a command button. Then create an &quot;OK&quot; button on that form, and put for its click event:<br><br>Me.Visible=false<br><br>You'll probably want to include some code to handle what happens if the user puts in something not in a date format or leaves it blank. In the code above, leaving the date blank simply exits the sub without setting selected date.<br><br>When you open the form, because it's in dialog mode, nothing can happen until it's gone from the screen. By setting its visibility to false, you're letting the user escape back to the original form, but the date form is still open, and the value of its controls are still accessible. Once you've gotten the value, either close it, or keep it open and invisible for faster loading if you use it often.<br><br>You could also make SelectedDate a Private variable for the calling form and have more flexibility with what you will do with it.<br><br>Charles<br><br>
 
Hi Charles,<br><br>the &quot;Visible&quot;-tip is indeed usefull, I didn't think about it that way, so thanks. However :-( this doesn't solve my problem: it works fine that way when you call the GetMyDate-form from another form which is what I would call something static. However I would like to call the form from something dynamic i.e. running code. Even when I open the form in modal status the code doesn't stop from running...:-(<br><br>Greetings,<br><br>Dirk
 
dirkg,<br>i've faced this problem b4, so i think you have to make the following edit to your function...<br><br>Function CustomDateForm() as Date <br>' this will ensure that nothing happen until the user closes th frmDateForm<br>docmd.openform (&quot;frmDateForm&quot;),,,,, acDialog<br><br>CustomDateForm = globalDate<br>your code ......<br><br>end function<br><br>just something left, you have to assign the value you want to get from &quot;frmDateForm&quot; to a public variable let's say &quot;globalDate&quot; when the user closes frmDateForm.<br><br>private sub frmDateForm_Unload()<br>&nbsp;globalDate = me.text2&nbsp;&nbsp;&nbsp;&quot; the text box that holds the value you want&quot;<br>end sub<br><br>for sure you have to declare that public variable in moudle tab, just as DougP said.<br><br>I hope that would help you,,, <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
yep, the acDialog was the key to the solution...so simple and yet it has taken me so long...THANKS FOR YOUR HELP!!<br><br>Greetings,<br><br>Dirk<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top