Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 23rd, 2005, 11:11 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Yorba Linda, California, USA.
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default talking to all txtBoxes via loop

Could someone point me in the right direction, please? I'm trying to lock all textboxes on a form (and eventually subform) via the click event of a button. Instead of hardcoding the lock for each textbox I would like to just loop through. I'm getting runtime error #13 "Type mismatch" with this code. I tried adding "next textbox" and got the same error. WHere did I err?

Thank you,

Loralee

Dim frmForm As Form
Dim txtBox As TextBox

Set frmForm = Me

For Each txtBox In frmForm
    txtBox.Locked = True
Next

End Sub

Reply With Quote
  #2 (permalink)  
Old September 23rd, 2005, 11:39 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

What you really want is a Control Array, but I don't think VBA supports that. Try this, I modified it from some code I found in the Excel VBA forum.

dim bx as object
for each bx in controls
   if left(bx.name,1)="t" then
      bx.Locked=true
   end if
next

Let me know if that works, if not, I know I have done this before, it's just a matter of finding out where!

Mike

Mike
EchoVue.com
Reply With Quote
  #3 (permalink)  
Old September 23rd, 2005, 12:14 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

LoraLee,

This works:

    Dim ctl As Control
    For Each ctl In Me.Controls
       With ctl
       Select Case .ControlType
           Case acTextBox
               ctl.locked = true
       End Select
       End With
    Next

Kevin


dartcoach
Reply With Quote
  #4 (permalink)  
Old September 27th, 2005, 11:26 PM
Friend of Wrox
 
Join Date: Jul 2005
Location: Oklahoma City, OK, USA.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you are wanting to prevcnt a users from changing the data on a form, why not just set the form's and subform's AllowEdits property to false.

Boyd
"Hi Tech Coach"
Access Based Accounting/Business Solutions developer.
http://www.officeprogramming.com
Reply With Quote
  #5 (permalink)  
Old September 28th, 2005, 09:02 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Yorba Linda, California, USA.
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank you all!
As far as the allowedits property = false, I tried that in a previous project and couldn't get it to work. Is there another argument somewhere that needs to be set also so it works?

Loralee

Reply With Quote
  #6 (permalink)  
Old September 28th, 2005, 09:10 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Loralee,
Do you want these textboxes always locked? Or just when someone clicks a button, or if they enter a particular value into another field?

Kevin

dartcoach
Reply With Quote
  #7 (permalink)  
Old September 29th, 2005, 10:41 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Yorba Linda, California, USA.
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default

I want to lock the textboxes (default) and supply a button that will unlock them. The button will only be visible if user has certain permissions. It's just a little more protection for our data. I'd rather loop through the collection than hardcode for each txtbox.

[It's not an elegant solution but opening the form as readonly via docmd caused subforms that are not populated to be blank. (Really blank- No objects visible- my uneducated guess is the foreign key on the SF is null and it falls flat on load??)]

Any ideas?

Thanks,

Loralee



Reply With Quote
  #8 (permalink)  
Old September 30th, 2005, 02:29 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

OK, Loralee --,
In the on open, or on load event of the form, the code I gave you earlier put inside an IF condition along with making the button visible. If the user has authority, the button is visible, along with making the fields available for editing. Make sense?

Kevin

dartcoach
Reply With Quote
  #9 (permalink)  
Old October 6th, 2005, 03:42 PM
Friend of Wrox
Points: 3,947, Level: 26
Points: 3,947, Level: 26 Points: 3,947, Level: 26 Points: 3,947, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,150
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

You may have checkboxes and option groups in there you may want to lock later on. Instead of locking the textboxes, put this on the button's ON CLICK event (assuming only authorized people can see it):

Me.AllowAdditions = Not Me.AllowAdditions
Me.AllowEdits = Not Me.AllowEdits
Me.AllowDeletions = Not Me.AllowDeletions

This will toggle the read/write on or off depending on the state they are just before you click the button. On the form's ON OPEN event, make sure you turn them off as the default.

Me.AllowAdditions = False
Me.AllowEdits = False
Me.AllowDeletions = False

You could also put a label (white letters) somewhere and do this to it. Whenever the editing, etc. is allowed you can do this

Me.lblRW.Caption = "EDIT"
Me.lblRW.BackColor = vbGreen

and when you DON'T allow editing

Me.lblRW.Caption = "READ ONLY"
Me.lblRW.BackColor = vbRed


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #10 (permalink)  
Old October 6th, 2005, 10:11 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Yorba Linda, California, USA.
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks, Greg. I'll give it a try this weekend.

Is there another property I have to also toggle somewhere? Last year I was playing with those properties and couldn'tget them to protect the data, and thought perhaps there was something else I missed ?????

Loralee

Reply With Quote
Reply


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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
talking to ms outlook from app wildt ASP.NET 1.x and 2.0 Application Design 0 March 24th, 2005 12:05 PM
Talking classes in VB6 James Diamond Pro VB 6 23 March 3rd, 2004 04:53 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 07:46 AM
SQL Server 7.0 talking to SQL Server 2000 msavage SQL Server 2000 1 August 20th, 2003 01:59 AM



All times are GMT -4. The time now is 07:27 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.