A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

variables



 
 
Thread Tools Display Modes
  #1  
Old February 9th, 2010, 01:12 PM posted to microsoft.public.access.gettingstarted
kary via AccessMonster.com
external usenet poster
 
Posts: 8
Default variables

Hi
I have assigned a variable called StPracLock as follows:
StPracLock = "Forms!Results1.Mod" & stMod & "Ass" & StAssNo & "Prac.Locked =
False"
Now I want to run the command by typing in the variable name but, ofcourse,
it doesn't work! (Comes up with "COmpile Error, Sub,Function,Procedure
expected) Can anyone help me. I have a number of fields to lock/unlock
depending on the Module (stMod) and Assignment (StAssNo) selected.
Thank you
Kary

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201002/1

  #2  
Old February 9th, 2010, 01:24 PM posted to microsoft.public.access.gettingstarted
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default variables

Why "of course", unless you mean that if it worked you would not be posting
the question? In what way does it not work (error message, incorrect string,
computer explodes)?

Where are you typing the variable names? How are those entries assigned to
the variables? Are the variables declared anywhere? What type of variables
are they (string, variant, long, or what exactly)? I assume they are strings,
but I can't be sure. Please post a sample of how the string would look with
the appropriate values inserted.

kary wrote:
Hi
I have assigned a variable called StPracLock as follows:
StPracLock = "Forms!Results1.Mod" & stMod & "Ass" & StAssNo & "Prac.Locked =
False"
Now I want to run the command by typing in the variable name but, ofcourse,
it doesn't work! (Comes up with "COmpile Error, Sub,Function,Procedure
expected) Can anyone help me. I have a number of fields to lock/unlock
depending on the Module (stMod) and Assignment (StAssNo) selected.
Thank you
Kary


--
Message posted via http://www.accessmonster.com

  #3  
Old February 9th, 2010, 01:45 PM posted to microsoft.public.access.gettingstarted
kary via AccessMonster.com
external usenet poster
 
Posts: 8
Default variables

Thanks BruceM for the quick reply!
I am declaring the variables as a string at the beginning of the procedure.

I want to unlock/enable/make visible various controls on a form using the
commands:
Forms!Results1.Mod1Ass2Prac.Locked = False
Forms!Results1.Mod1Ass2Prac.Enabled = True
Forms!Results1.Mod1Ass2Prac.Visible = True

The number after "Mod" and "Ass" will change depending on the
module/assignment selected on the form. When I press OK on the form, the
variables StMod and StAss will be set depending on the module/assignment
selected.

Then I call a module which will contain this code (this is to cut down on the
amount code). However, I don't know how to then "execute" the variable so
that it runs the code.
Hope this makes sense! Kary


BruceM wrote:
Why "of course", unless you mean that if it worked you would not be posting
the question? In what way does it not work (error message, incorrect string,
computer explodes)?

Where are you typing the variable names? How are those entries assigned to
the variables? Are the variables declared anywhere? What type of variables
are they (string, variant, long, or what exactly)? I assume they are strings,
but I can't be sure. Please post a sample of how the string would look with
the appropriate values inserted.

Hi
I have assigned a variable called StPracLock as follows:

[quoted text clipped - 6 lines]
Thank you
Kary


--
Message posted via http://www.accessmonster.com

  #4  
Old February 9th, 2010, 02:28 PM posted to microsoft.public.access.gettingstarted
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default variables

First, I don't think you can use a string in that way to lock, enable, etc.
controls. You can assemble the control name:

Dim stPracLock as String, stMod as String, stAssNo as String

stMod = ?
stAssNo = ??
stPracLock = "Mod" & stMod & "Ass" & StAssNo & "Prac"

Then:

Me.Controls(stPracLock).Enabled = False

For several properties you could do:

With Me.Controls(stPracLock)
.Enabled = False
.Locked = True
.Visible = True
End With

If this is in a module other than the form's code module:

Dim frm As Form
Dim stPracLock as String, stMod as String, stAssNo as String

stMod = ?
stAssNo = ??
stPracLock = "Mod" & stMod & "Ass" & StAssNo & "Prac"

With frm.Controls(stPracLock)
.Enabled = False
.Locked = True
.Visible = True
End With

However, since you are already hard-coding the from name it seems you are
performing all of these actions for a single form, so there is no need for
code anwhere other than the form's code module. The method that uses frm is
if you are applying the code to several forms, and need the code to be in a
standalone code module.

You are not calling a module, which is the entire body of code associated
with a form or in a standalone module, but rather calling a sub or function.

This brings us back to the question of where the user inputs the values to be
used. Only you can answer that question. Where do stMod and stAssNo get
their values? This is not asking where they are declared, but rather how
they receive the values 1 and 2.

I do not know what you mean by "execute" the variable. I could take a few
guesses, but it would be better if you describe exactly what is to happen.

kary wrote:
Thanks BruceM for the quick reply!
I am declaring the variables as a string at the beginning of the procedure.

I want to unlock/enable/make visible various controls on a form using the
commands:
Forms!Results1.Mod1Ass2Prac.Locked = False
Forms!Results1.Mod1Ass2Prac.Enabled = True
Forms!Results1.Mod1Ass2Prac.Visible = True

The number after "Mod" and "Ass" will change depending on the
module/assignment selected on the form. When I press OK on the form, the
variables StMod and StAss will be set depending on the module/assignment
selected.

Then I call a module which will contain this code (this is to cut down on the
amount code). However, I don't know how to then "execute" the variable so
that it runs the code.
Hope this makes sense! Kary

Why "of course", unless you mean that if it worked you would not be posting
the question? In what way does it not work (error message, incorrect string,

[quoted text clipped - 11 lines]
Thank you
Kary


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201002/1

  #5  
Old February 9th, 2010, 03:12 PM posted to microsoft.public.access.gettingstarted
kary via AccessMonster.com
external usenet poster
 
Posts: 8
Default variables

Hi Bruce,
I need a bit of time to try this but I think you've solved my query. I see
now that I need to split the control name which I'm storing in the variable
(stPracLock ="Mod" & stMod & "Ass" & StAssNo & "Prac") from the control value
(.Enabled = False). Many thanks for your time - I really appreciate it. Kary

BruceM wrote:
First, I don't think you can use a string in that way to lock, enable, etc.
controls. You can assemble the control name:

Dim stPracLock as String, stMod as String, stAssNo as String

stMod = ?
stAssNo = ??
stPracLock = "Mod" & stMod & "Ass" & StAssNo & "Prac"

Then:

Me.Controls(stPracLock).Enabled = False

For several properties you could do:

With Me.Controls(stPracLock)
.Enabled = False
.Locked = True
.Visible = True
End With

If this is in a module other than the form's code module:

Dim frm As Form
Dim stPracLock as String, stMod as String, stAssNo as String

stMod = ?
stAssNo = ??
stPracLock = "Mod" & stMod & "Ass" & StAssNo & "Prac"

With frm.Controls(stPracLock)
.Enabled = False
.Locked = True
.Visible = True
End With

However, since you are already hard-coding the from name it seems you are
performing all of these actions for a single form, so there is no need for
code anwhere other than the form's code module. The method that uses frm is
if you are applying the code to several forms, and need the code to be in a
standalone code module.

You are not calling a module, which is the entire body of code associated
with a form or in a standalone module, but rather calling a sub or function.

This brings us back to the question of where the user inputs the values to be
used. Only you can answer that question. Where do stMod and stAssNo get
their values? This is not asking where they are declared, but rather how
they receive the values 1 and 2.

I do not know what you mean by "execute" the variable. I could take a few
guesses, but it would be better if you describe exactly what is to happen.

Thanks BruceM for the quick reply!
I am declaring the variables as a string at the beginning of the procedure.

[quoted text clipped - 20 lines]
Thank you
Kary


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201002/1

  #6  
Old February 9th, 2010, 03:57 PM posted to microsoft.public.access.gettingstarted
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default variables

As a point of terminology, Enabled, Visible, Locked, and the like are
properties, not values.

Note that if all of this is in a single form you can use the Me. prefix as I
showed rather than the fully qualified name (Forms!...). Note too that you
need to use syntax along the lines of:

Me.Controls("ControlName").Enabled = False
or
Me.Controls(stPracLock).Enabled = False

to use a string value for the control name. You can't treat the whole
expression as a string.


kary wrote:
Hi Bruce,
I need a bit of time to try this but I think you've solved my query. I see
now that I need to split the control name which I'm storing in the variable
(stPracLock ="Mod" & stMod & "Ass" & StAssNo & "Prac") from the control value
(.Enabled = False). Many thanks for your time - I really appreciate it. Kary

First, I don't think you can use a string in that way to lock, enable, etc.
controls. You can assemble the control name:

[quoted text clipped - 54 lines]
Thank you
Kary


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201002/1

  #7  
Old February 9th, 2010, 06:56 PM posted to microsoft.public.access.gettingstarted
kary via AccessMonster.com
external usenet poster
 
Posts: 8
Default variables

Hi Bruce
Thanks, the right terminology certainly helps! I have now got the following:

1) A Select Case statement to set the value of stMod and stAssNo
2) A Call statement to call a sub (Call ShowControls(stMod, stAssNo))
3) In ShowControls:
Public Sub ShowControls(stMod, stAssNo)

Dim stPrac As String
Dim stAcad As String

stPrac = "Forms!Results1.Mod" & stMod & "Ass" & stAssNo & "Prac"
stAcad = "Forms!Results1.Mod" & stMod & "Ass" & stAssNo & "Acad"

'Forms!Results1!Mod1Ass1Acad.Visible = True '-- (a)

With Me.Controls(stPrac)
.Locked = False
.Visible = True
End With

With Me.Controls(stAcad)
.Locked = False
.Visible = True
End With

End Sub

Now when I run it, it goes through the select statement, passes the variables
to the ShowControls sub and then gives the error message: "Office can't find
the field 'Forms!Results1!Mod1Ass1Prac' referred to in your expression."
However, the code which I've marked with (a) above which is currently
commented out does work.
Thank you for your help, Kary

BruceM wrote:
As a point of terminology, Enabled, Visible, Locked, and the like are
properties, not values.

Note that if all of this is in a single form you can use the Me. prefix as I
showed rather than the fully qualified name (Forms!...). Note too that you
need to use syntax along the lines of:

Me.Controls("ControlName").Enabled = False
or
Me.Controls(stPracLock).Enabled = False

to use a string value for the control name. You can't treat the whole
expression as a string.

Hi Bruce,
I need a bit of time to try this but I think you've solved my query. I see

[quoted text clipped - 7 lines]
Thank you
Kary


--
Message posted via http://www.accessmonster.com

  #8  
Old February 9th, 2010, 07:33 PM posted to microsoft.public.access.gettingstarted
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default variables

Me.Controls("ControlName") uses the name of the control only. "Forms!
Results1" is extraneous.

stPrac = "Mod" & stMod & "Ass" & stAssNo & "Prac"
stAcad = "Mod" & stMod & "Ass" & stAssNo & "Acad"

The rest of the code looks OK.

If you need to see what a string (or any variable) looks like after it is
assmbled, add this line of code after you have set the variable (in this case,
directly after the stAcad line of code):
Debug.Print stPrac
Debug.Print stAcac

After you run the code, press Ctrl + G to open the immediate code window.
The strings will be shown there.

It's best to remove or comment out the Debug lines of code after you are done
testing (before you start using the database for real).

kary wrote:
Hi Bruce
Thanks, the right terminology certainly helps! I have now got the following:

1) A Select Case statement to set the value of stMod and stAssNo
2) A Call statement to call a sub (Call ShowControls(stMod, stAssNo))
3) In ShowControls:
Public Sub ShowControls(stMod, stAssNo)

Dim stPrac As String
Dim stAcad As String

stPrac = "Forms!Results1.Mod" & stMod & "Ass" & stAssNo & "Prac"
stAcad = "Forms!Results1.Mod" & stMod & "Ass" & stAssNo & "Acad"

'Forms!Results1!Mod1Ass1Acad.Visible = True '-- (a)

With Me.Controls(stPrac)
.Locked = False
.Visible = True
End With

With Me.Controls(stAcad)
.Locked = False
.Visible = True
End With

End Sub

Now when I run it, it goes through the select statement, passes the variables
to the ShowControls sub and then gives the error message: "Office can't find
the field 'Forms!Results1!Mod1Ass1Prac' referred to in your expression."
However, the code which I've marked with (a) above which is currently
commented out does work.
Thank you for your help, Kary

As a point of terminology, Enabled, Visible, Locked, and the like are
properties, not values.

[quoted text clipped - 15 lines]
Thank you
Kary


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201002/1

  #9  
Old February 9th, 2010, 07:52 PM posted to microsoft.public.access.gettingstarted
kary via AccessMonster.com
external usenet poster
 
Posts: 8
Default variables

Yes! You did it. Thank you SO much - you're a star!
Kary

BruceM wrote:
Me.Controls("ControlName") uses the name of the control only. "Forms!
Results1" is extraneous.

stPrac = "Mod" & stMod & "Ass" & stAssNo & "Prac"
stAcad = "Mod" & stMod & "Ass" & stAssNo & "Acad"

The rest of the code looks OK.

If you need to see what a string (or any variable) looks like after it is
assmbled, add this line of code after you have set the variable (in this case,
directly after the stAcad line of code):
Debug.Print stPrac
Debug.Print stAcac

After you run the code, press Ctrl + G to open the immediate code window.
The strings will be shown there.

It's best to remove or comment out the Debug lines of code after you are done
testing (before you start using the database for real).

Hi Bruce
Thanks, the right terminology certainly helps! I have now got the following:

[quoted text clipped - 36 lines]
Thank you
Kary


--
Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:30 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.