Referencing a text box on a form from a module

Groundrush

Registered User.
Local time
Today, 22:57
Joined
Apr 14, 2002
Messages
1,376
What am I doing wrong?

I'm trying to reference a field in a form via a module run from a command button on the same form but it's not working

form is called "frmSendSMS"
field is called "txtMobileNo

This is part of the code in the module
Code:
Option Compare Database
Global Const strClickatell_From = "&from=Forms!frmSendSMS!txtMobileNo" ' Staff


Much appreciated if anyone can spot & tell me what I'm doing wrong

Thanks
 
First of all the form must be open in order to reference the control on the form.

One method of referring to a control is

X = Forms("FormName")("ControlName")
 
First of all the form must be open in order to reference the control on the form.

One method of referring to a control is

X = Forms("FormName")("ControlName")

Hi DCrake,

Yes my form is open when the module if called, I thought perhaps my syntax was incorrect.

Would I need to do something like this?

Code:
X = Forms("frmSendSMS")("txtMobileNo")
Global Const strClickatell_From = "&from=X" ' Staff

I get a compile error when I tried :confused:
 
What are you trying to do with the global const?

Don't understand "&from=X"

From what I can remember Constants cannot be set using variables, however you can setup a gloabal variable

Public VariableName As Long/Integer/String/Variant,Etc
 
The code I am using originally allowed me to store one Cell/Mobile No

Code:
Global Const strClickatell_From = "&from=44743649017"

When a SMS is sent it displays that no as the sender to whover reads the message

The problem there was that I could only store one no & not the phone number of the actual person who used the application.
I then tried to reference a text box that displayed the users phone no using

Code:
Global Const strClickatell_From = "&from=Forms!frmSendSMS!txtMobileNo"

That didin't work so now I'm trying your suggestion using
Code:
X = Forms("frmSendSMS")("txtMobileNo")
Global Const strClickatell_From = "&from=X"

which I'm getting wrong.

I was hoping that it was a simple error but it looks like it's not going to be easy.
 
You can't set constants with code. You set constants by manually typing it in the module.
 
Yes but what the &From supposed to be?

Also you need to parse the X, such as "&from=" & X
 
It looks like it's being read by some external software that's probably webbed, maybe like a scripting software.

Even with that it will throw an error. A constant should be a preset value, that's why they are constants. Setting its value via another variable or field it wouldn't like that. I don't see why the OP isn't getting the value directly from the table instead?
 

Users who are viewing this thread

Back
Top Bottom