Functions / Call Procedure.

User avatar
Steve_in_Kent
4StarLounger
Posts: 419
Joined: 04 Feb 2010, 11:46

Functions / Call Procedure.

Post by Steve_in_Kent »

I've written a Function, that behaves a bit differently from other code that i've written.

this function calls a form, that requires a number to be entered. its doing that here.. however, its arriving at the
messagebox, but ofc,, has no number to work with, because the user hasn't selected one yet.

Whats the best way, of returning to the code, but only when the user has either a) selected a number or b) cancelled the operation (there is a button on the form, for this)

example code.

Code: Select all

Private Sub Command3_Click()
Call NumberBox(2)
...
...
...
msg box 'You Selected number '' & Mynumber
...
...  more code

Code: Select all

Function NumberBox(X As Integer)
' this opens up a number box to select a number. X being the number of digits.
MyNumber = 0
DoCmd.OpenForm "Inputweek", acNormal
End Function
----------------------------------------------------------------------------------------
Owing at LEAST 34 beers to other helpful forum members. Especially HansV!

User avatar
HansV
Administrator
Posts: 78548
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Functions / Call Procedure.

Post by HansV »

The code is confusing: your function NumberBox takes an argument X but as far as I can see, X isn't used anywhere. What is its purpose?
Best wishes,
Hans

User avatar
Steve_in_Kent
4StarLounger
Posts: 419
Joined: 04 Feb 2010, 11:46

Re: Functions / Call Procedure.

Post by Steve_in_Kent »

X is the number of chars needed by the Numberbox.

the numberbox is form with buttons on it, to select a number, with a text box below it, for the actual number.

as each number is entered, another function is called (LengthCheck), to determine if the LengthRequired (Global), has been reached.

the reason for this , is to allow whatever length of numbers i want, then will re-use it anytime i want a number.

so its in effect, a fancy inputbox.
----------------------------------------------------------------------------------------
Owing at LEAST 34 beers to other helpful forum members. Especially HansV!

User avatar
HansV
Administrator
Posts: 78548
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Functions / Call Procedure.

Post by HansV »

OK, but you don't do anything with the value of X - at least not visibly.

Anyway, to prevent the code from continuing before the user has closed the InputWeek form, use

DoCmd.OpenForm FormName:="Inputweek", WindowMode:=acDialog
Best wishes,
Hans

User avatar
Steve_in_Kent
4StarLounger
Posts: 419
Joined: 04 Feb 2010, 11:46

Re: Functions / Call Procedure.

Post by Steve_in_Kent »

perfect hans tyvm
:clapping:
----------------------------------------------------------------------------------------
Owing at LEAST 34 beers to other helpful forum members. Especially HansV!