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  

A Better Way To Code This



 
 
Thread Tools Display Modes
  #1  
Old October 15th, 2005, 11:26 PM
DS
external usenet poster
 
Posts: n/a
Default A Better Way To Code This

Is there a better way to code this, Like a global command or something?
Thanks
DS

Private Sub Command43_Click()
On Error GoTo Err_Command43_Click
DoCmd.RunCommand acCmdSaveRecord
Me.BusinessName.Enabled = False
Me.BusinessName.Locked = True
Me.FName.Enabled = False
Me.FName.Locked = True
Me.LName.Enabled = False
Me.LName.Locked = True
Me.Address.Enabled = False
Me.Address.Locked = True
Me.Apt.Enabled = False
Me.Apt.Locked = True
Me.City.Enabled = False
Me.City.Locked = True
Me.State.Enabled = False
Me.State.Locked = True
Me.ZipCode.Enabled = False
Me.ZipCode.Locked = True
Me.Tel.Enabled = False
Me.Tel.Locked = True
Me.Ext.Enabled = False
Me.Ext.Locked = True
Me.Fax.Enabled = False
Me.Fax.Locked = True
Me.EMail.Enabled = False
Me.EMail.Locked = True
Me.HouseAccount.Enabled = False
Me.HouseAccount.Locked = True
Me.CreditLimit.Enabled = False
Me.CreditLimit.Locked = True
Me.Command33.Visible = True
Me.Command34.Visible = True
Me.Command42.Visible = True
Me.Command42.SetFocus
Me.Command43.Visible = False
Me.Command44.Visible = True
Me.List40.Requery
Exit_Command43_Click:
Exit Sub

Err_Command43_Click:
MsgBox Err.Description
Resume Exit_Command43_Click

End Sub
  #2  
Old October 15th, 2005, 11:47 PM
tina
external usenet poster
 
Posts: n/a
Default A Better Way To Code This

well, without knowing the context of what you're doing, it's hard to suggest
a specific "better" way. for instance, if the controls that you enumerated
constitute *all* the editable controls on the form (presumably you're
working with a form), it might work equally well to simply set the form's
AllowEdits property to False - and it's certainly much shorter and easier.
or, if all the enumerated controls are textboxes, you could write code to
loop through all the controls on the form, and set the Enabled and Locked
properties of all controls that are textboxes. or, if you need to pick and
choose certain controls to be disabled and locked, you might set the Tag
property of those specific controls to....anything, actually, such as "lock"
or just an "x", and run a loop through all form controls, setting the
Enabled and Locked properties of those controls whose Tag property equals
"lock" or "x" or "whatever".

keep in mind that, whatever method you choose to lock certain controls, you
will probably need to also unlock them where appropriate - either
automatically, or by allowing the user to unlock them manually.

hth


"DS" wrote in message
...
Is there a better way to code this, Like a global command or something?
Thanks
DS

Private Sub Command43_Click()
On Error GoTo Err_Command43_Click
DoCmd.RunCommand acCmdSaveRecord
Me.BusinessName.Enabled = False
Me.BusinessName.Locked = True
Me.FName.Enabled = False
Me.FName.Locked = True
Me.LName.Enabled = False
Me.LName.Locked = True
Me.Address.Enabled = False
Me.Address.Locked = True
Me.Apt.Enabled = False
Me.Apt.Locked = True
Me.City.Enabled = False
Me.City.Locked = True
Me.State.Enabled = False
Me.State.Locked = True
Me.ZipCode.Enabled = False
Me.ZipCode.Locked = True
Me.Tel.Enabled = False
Me.Tel.Locked = True
Me.Ext.Enabled = False
Me.Ext.Locked = True
Me.Fax.Enabled = False
Me.Fax.Locked = True
Me.EMail.Enabled = False
Me.EMail.Locked = True
Me.HouseAccount.Enabled = False
Me.HouseAccount.Locked = True
Me.CreditLimit.Enabled = False
Me.CreditLimit.Locked = True
Me.Command33.Visible = True
Me.Command34.Visible = True
Me.Command42.Visible = True
Me.Command42.SetFocus
Me.Command43.Visible = False
Me.Command44.Visible = True
Me.List40.Requery
Exit_Command43_Click:
Exit Sub

Err_Command43_Click:
MsgBox Err.Description
Resume Exit_Command43_Click

End Sub



  #3  
Old October 16th, 2005, 12:25 AM
Albert D.Kallal
external usenet poster
 
Posts: n/a
Default A Better Way To Code This

I guess the question is "which" set of controls do you want to operate on.

There is a property in each control that is "free to" use for whatever you
want. It is called the tag property.

So, for controls that you want to operator on, you can make up a value for
the "tag" property, and use that
(you can find the tag property in the "other" tab)

So, you could while in design mode set the tag value. Lets assume you set
the "tag" value to

Set1

So, now, you code could look like:


Dim c As Control

For Each c In Controls
If c.tab = "set1" Then
c.Enabled = False
c.Locked = True
End If
Next c

There is many many ways to skin a cat here.

You could use:

Dim strFields As String
Dim v As Variant
Dim i As Integer

v = Split("BusinessName,FName,LName,Address,Apt,City,S tate,ZipCode", ",")

For i = 0 To UBound(v)
Me(v(i)).Enabled = False
Me(v(i)).Locked = True
Next i


And, of course, you likely could setup the routine to pass a var

So, you go:

Call SetControls(True) ' to enable contorls
Call SetContorls(False) ' to disable contorls

You routine then looks like

Sub SetControls(bolOnOff as boolean)

For Each c In Controls
If c.tab = "set1" Then
c.Enabled = bolOnOff
c.Locked = not(bolOnOff)
End If
Next c


There is even more approaches, but the above has some good ideas to get you
going....


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada

http://www.members.shaw.ca/AlbertKallal


  #4  
Old October 16th, 2005, 06:26 AM
DS
external usenet poster
 
Posts: n/a
Default A Better Way To Code This

tina wrote:

well, without knowing the context of what you're doing, it's hard to suggest
a specific "better" way. for instance, if the controls that you enumerated
constitute *all* the editable controls on the form (presumably you're
working with a form), it might work equally well to simply set the form's
AllowEdits property to False - and it's certainly much shorter and easier.
or, if all the enumerated controls are textboxes, you could write code to
loop through all the controls on the form, and set the Enabled and Locked
properties of all controls that are textboxes. or, if you need to pick and
choose certain controls to be disabled and locked, you might set the Tag
property of those specific controls to....anything, actually, such as "lock"
or just an "x", and run a loop through all form controls, setting the
Enabled and Locked properties of those controls whose Tag property equals
"lock" or "x" or "whatever".

keep in mind that, whatever method you choose to lock certain controls, you
will probably need to also unlock them where appropriate - either
automatically, or by allowing the user to unlock them manually.

hth


"DS" wrote in message
...

Is there a better way to code this, Like a global command or something?
Thanks
DS

Private Sub Command43_Click()
On Error GoTo Err_Command43_Click
DoCmd.RunCommand acCmdSaveRecord
Me.BusinessName.Enabled = False
Me.BusinessName.Locked = True
Me.FName.Enabled = False
Me.FName.Locked = True
Me.LName.Enabled = False
Me.LName.Locked = True
Me.Address.Enabled = False
Me.Address.Locked = True
Me.Apt.Enabled = False
Me.Apt.Locked = True
Me.City.Enabled = False
Me.City.Locked = True
Me.State.Enabled = False
Me.State.Locked = True
Me.ZipCode.Enabled = False
Me.ZipCode.Locked = True
Me.Tel.Enabled = False
Me.Tel.Locked = True
Me.Ext.Enabled = False
Me.Ext.Locked = True
Me.Fax.Enabled = False
Me.Fax.Locked = True
Me.EMail.Enabled = False
Me.EMail.Locked = True
Me.HouseAccount.Enabled = False
Me.HouseAccount.Locked = True
Me.CreditLimit.Enabled = False
Me.CreditLimit.Locked = True
Me.Command33.Visible = True
Me.Command34.Visible = True
Me.Command42.Visible = True
Me.Command42.SetFocus
Me.Command43.Visible = False
Me.Command44.Visible = True
Me.List40.Requery
Exit_Command43_Click:
Exit Sub

Err_Command43_Click:
MsgBox Err.Description
Resume Exit_Command43_Click

End Sub




Basiclly I want all of the forms textboxs that are used for data entry
on the form locked until the user clicks on a command button to either
add a new record or another command button to edit the record. I also
have a listbox on the form that is used to find records that the user
clicks on if this matters.
Thanks
DS
  #5  
Old October 16th, 2005, 01:40 PM
Ken Snell [MVP]
external usenet poster
 
Posts: n/a
Default A Better Way To Code This

This is a time when the Tag property of the controls is useful. If you put a
value in the Tag property of the controls that you want to enable/disable
and lock/unlock, the code becomes much simpler.

For example, let's say you put
1
in the Tag property of all these controls. Then the code becomes this:

Private Sub Command43_Click()
Dim ctl As Control
On Error GoTo Err_Command43_Click
DoCmd.RunCommand acCmdSaveRecord
For Each ctl in Me.Controls
If ctl.Tag = "1" Then
ctl.Enabled = False
ctl.Locked = True
End If
Next ctl
Me.List40.Requery
Exit_Command43_Click:
Exit Sub

Err_Command43_Click:
MsgBox Err.Description
Resume Exit_Command43_Click

End Sub
--

Ken Snell
MS ACCESS MVP

"DS" wrote in message
...
tina wrote:

well, without knowing the context of what you're doing, it's hard to
suggest
a specific "better" way. for instance, if the controls that you
enumerated
constitute *all* the editable controls on the form (presumably you're
working with a form), it might work equally well to simply set the form's
AllowEdits property to False - and it's certainly much shorter and
easier.
or, if all the enumerated controls are textboxes, you could write code to
loop through all the controls on the form, and set the Enabled and Locked
properties of all controls that are textboxes. or, if you need to pick
and
choose certain controls to be disabled and locked, you might set the Tag
property of those specific controls to....anything, actually, such as
"lock"
or just an "x", and run a loop through all form controls, setting the
Enabled and Locked properties of those controls whose Tag property equals
"lock" or "x" or "whatever".

keep in mind that, whatever method you choose to lock certain controls,
you
will probably need to also unlock them where appropriate - either
automatically, or by allowing the user to unlock them manually.

hth


"DS" wrote in message
...

Is there a better way to code this, Like a global command or something?
Thanks
DS

Private Sub Command43_Click()
On Error GoTo Err_Command43_Click
DoCmd.RunCommand acCmdSaveRecord
Me.BusinessName.Enabled = False
Me.BusinessName.Locked = True
Me.FName.Enabled = False
Me.FName.Locked = True
Me.LName.Enabled = False
Me.LName.Locked = True
Me.Address.Enabled = False
Me.Address.Locked = True
Me.Apt.Enabled = False
Me.Apt.Locked = True
Me.City.Enabled = False
Me.City.Locked = True
Me.State.Enabled = False
Me.State.Locked = True
Me.ZipCode.Enabled = False
Me.ZipCode.Locked = True
Me.Tel.Enabled = False
Me.Tel.Locked = True
Me.Ext.Enabled = False
Me.Ext.Locked = True
Me.Fax.Enabled = False
Me.Fax.Locked = True
Me.EMail.Enabled = False
Me.EMail.Locked = True
Me.HouseAccount.Enabled = False
Me.HouseAccount.Locked = True
Me.CreditLimit.Enabled = False
Me.CreditLimit.Locked = True
Me.Command33.Visible = True
Me.Command34.Visible = True
Me.Command42.Visible = True
Me.Command42.SetFocus
Me.Command43.Visible = False
Me.Command44.Visible = True
Me.List40.Requery
Exit_Command43_Click:
Exit Sub

Err_Command43_Click:
MsgBox Err.Description
Resume Exit_Command43_Click

End Sub




Basiclly I want all of the forms textboxs that are used for data entry on
the form locked until the user clicks on a command button to either add a
new record or another command button to edit the record. I also have a
listbox on the form that is used to find records that the user clicks on
if this matters.
Thanks
DS



  #6  
Old October 16th, 2005, 08:19 PM
DS
external usenet poster
 
Posts: n/a
Default A Better Way To Code This

Ken Snell [MVP] wrote:
This is a time when the Tag property of the controls is useful. If you put a
value in the Tag property of the controls that you want to enable/disable
and lock/unlock, the code becomes much simpler.

For example, let's say you put
1
in the Tag property of all these controls. Then the code becomes this:

Private Sub Command43_Click()
Dim ctl As Control
On Error GoTo Err_Command43_Click
DoCmd.RunCommand acCmdSaveRecord
For Each ctl in Me.Controls
If ctl.Tag = "1" Then
ctl.Enabled = False
ctl.Locked = True
End If
Next ctl
Me.List40.Requery
Exit_Command43_Click:
Exit Sub

Err_Command43_Click:.
MsgBox Err.Description
Resume Exit_Command43_Click

End Sub

Wow thats cool! I'll give it a try. Beats setting all of those fields!
Thanks
DS
  #7  
Old October 17th, 2005, 04:10 AM
DS
external usenet poster
 
Posts: n/a
Default A Better Way To Code This

DS wrote:
Ken Snell [MVP] wrote:

This is a time when the Tag property of the controls is useful. If you
put a value in the Tag property of the controls that you want to
enable/disable and lock/unlock, the code becomes much simpler.

For example, let's say you put
1
in the Tag property of all these controls. Then the code becomes this:

Private Sub Command43_Click()
Dim ctl As Control
On Error GoTo Err_Command43_Click
DoCmd.RunCommand acCmdSaveRecord
For Each ctl in Me.Controls
If ctl.Tag = "1" Then
ctl.Enabled = False
ctl.Locked = True
End If
Next ctl
Me.List40.Requery
Exit_Command43_Click:
Exit SubKen,

Err_Command43_Click:. MsgBox Err.Description
Resume Exit_Command43_Click

End Sub


Wow thats cool! I'll give it a try. Beats setting all of those fields!
Thanks
DS

Ken This is the greatest thing since.....! It saves a ton of work.
Thank you so very much!
Sincerely
DS
  #8  
Old October 17th, 2005, 04:13 AM
DS
external usenet poster
 
Posts: n/a
Default A Better Way To Code This

Albert D.Kallal wrote:
I guess the question is "which" set of controls do you want to operate on.

There is a property in each control that is "free to" use for whatever you
want. It is called the tag property.

So, for controls that you want to operator on, you can make up a value for
the "tag" property, and use that
(you can find the tag property in the "other" tab)

So, you could while in design mode set the tag value. Lets assume you set
the "tag" value to

Set1

So, now, you code could look like:


Dim c As Control

For Each c In Controls
If c.tab = "set1" Then
c.Enabled = False
c.Locked = True
End If
Next c

There is many many ways to skin a cat here.

You could use:

Dim strFields As String
Dim v As Variant
Dim i As Integer

v = Split("BusinessName,FName,LName,Address,Apt,City,S tate,ZipCode", ",")

For i = 0 To UBound(v)
Me(v(i)).Enabled = False
Me(v(i)).Locked = True
Next i


And, of course, you likely could setup the routine to pass a var

So, you go:

Call SetControls(True) ' to enable contorls
Call SetContorls(False) ' to disable contorls

You routine then looks like

Sub SetControls(bolOnOff as boolean)

For Each c In Controls
If c.tab = "set1" Then
c.Enabled = bolOnOff
c.Locked = not(bolOnOff)
End If
Next c


There is even more approaches, but the above has some good ideas to get you
going....


Thank you Albert a whole lot of choices! This certanly makes life
easier and the cats safe !!!!
Once again Thank you Albert
Sincerely
DS
  #9  
Old October 17th, 2005, 04:47 AM
Ken Snell [MVP]
external usenet poster
 
Posts: n/a
Default A Better Way To Code This

You're welcome.

--

Ken Snell
MS ACCESS MVP

"DS" wrote in message
...
Ken This is the greatest thing since.....! It saves a ton of work. Thank
you so very much!
Sincerely
DS



 




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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Toolbars, Drop-Down Menus Rick New Users 1 September 21st, 2005 11:17 AM
0x80040109 error when sending from SSL SMTP krouse General Discussion 7 March 15th, 2005 01:55 AM
Excellent Navigation Method! Bill Mitchell Using Forms 3 December 16th, 2004 01:49 PM
Attn Sprinks - clarification on VB code babs Using Forms 6 December 11th, 2004 12:55 AM
Barcodes TarponZeke General Discussion 4 October 25th, 2004 08:04 PM


All times are GMT +1. The time now is 12:09 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.