Call Value in module

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Call Value in module

Post by burrina »

I have a form and a module for this example. Form is frmAlarms , module is modAlarms
I can call a Case number from module to fire on timer event for the form.
If I hard code it, no problem, it works.

SelectCase CommandNumber
Case is = 2
Case MsgBox = Forms!frmAlarms!txtFunctionName.Value ' Will this work?
I want to be able to enter whatever I want for Case 2, as a message and then have the timer event use it.
txtFunctionName is the textbox for the Case statement value on frmAlarms

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

Re: Call Value in module

Post by HansV »

Do you want the user to enter a value or do you want to use the value of txtFunctionName?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Call Value in module

Post by burrina »

This is my dilemma, I can use the module and call a command to be executed, like DoCmd.Beep
And If I hard code the Case statement it works as well.
What I'm trying to figure out is if the user enters a message in txtFunction that is not hard coded in the function will it work?
Not sure if it's possible to do both or not.

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Call Value in module

Post by burrina »

Again,unsure of my approach or syntax but here goes.
If IsNull Case.CommandNumber Then
Me.txtFunctionName = MsgBox & "'" & Me.txtFunctionName
End If

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

Re: Call Value in module

Post by HansV »

That won't work, but I still do not understand what you are trying to do...
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Call Value in module

Post by burrina »

Any value I use in the field txtFunctionName will work if its hard coded in the module.
If its not in the module then what are my options?
I can write in txtFunctionName Hi there and when the time event fires, the message will show up.
If the functionname is not in the module of course nothing will happen.
This db is for timed events to happen at whatever time is selected. Ex; Let me know when its time for lunch or make a beep sound at 5pm
This all works because they would be in the module hard coded.
If they are not is my question, how can I make it work?

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Call Value in module

Post by burrina »

Case is = 2
MsgBox = "Hi there"
rs!FuncationName = Me.txtFunctionName

Q is, Can I leave the MsgBox Null and populate it from the value in txtFuncationName ?

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Call Value in module

Post by burrina »

Hans, sorry for my poor communication skills. I think I now have the answer. Leave the hard coded variables in the module and if the variable does not exists then it will treat it as text.

I will play around with it a bit and post back later.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Call Value in module

Post by ChrisGreaves »

burrina wrote:
22 Dec 2020, 11:02
...Leave the hard coded variables in the module ...
Hi burrina ; this is probably not the place for a philosophical discussion on programming techniques, but if it were I would make the case that there should be no hard-coded variables in procedure code.
I can make a case for hard-coded labelled constants in procedure code: "Public Const lngcMonthsInYear as Long = 12" and then making use of the identifier "lngcMonthsInYear " within a procedure, but a value such as (example) The Number Of Branch Offices ought always be stored at run-time in a named variable.
I frequently make use of literal numeric values in procedure code while I am "getting it to work", but I [should] always replace the literal numeric value (12) with the symbolic value (lngcMonthsInYear) before I release the code.
Again, right now you need/want to get your code working, so we should not discuss this here. I mention it because I have caused myself so many problems in the past by leaving hard-coded variables in procedure code. They come back and bite me months or years after the code is released!
Cheers
Chris
An expensive day out: Wallet and Grimace

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Call Value in module

Post by burrina »

Thanks for the advice. It was hard enough getting the code to work in the 1st place.

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Call Value in module

Post by burrina »

Oh, FYI The code works perfectly, its just the user friendly setup that is the problem.
Thanks so much.

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Call Value in module

Post by burrina »

Hans, in all fairness to you it was my lack of communicating that was the issue. I have since solved the problem.
I apologize for my unclear post.
Thanks,

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

Re: Call Value in module

Post by HansV »

I'm glad you were able to solve it.
Best wishes,
Hans