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 VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 Search this Thread Display Modes
  #1 (permalink)  
Old May 11th, 2007, 08:39 AM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default function - change forms txtbox properties

--------------------------------------------------------------------------------

All I want to do is a create function that checks the text in a form field, and then dependant on value assign a font color. So my code I was thinking would look something like this

Dim txt As textBox

set txt = txtBoxName

FormatTxtBox(txtBoxName)

Public Function FormatTxtBox(txt As TextBox)

If txt.text="Not Available" Then
txt.foreColor="Red"
end if


End Function

I just get a runtime error 424 Object required??

Pls Help


Reply With Quote
  #2 (permalink)  
Old May 11th, 2007, 09:00 AM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Before anyone suggests conditional formatting there are 10 Possible values. I think conditional formatting only allows for a maximum of three

Reply With Quote
  #3 (permalink)  
Old May 11th, 2007, 10:03 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

What event are you putting this on?

Anyway, I do something like this:

Dim sText As String

If IsNull(Me.txtYourTextBox) or Me.txtYourTextBox = "" Then
   sText = "Some value"
Else
   sText = Me.txtYourTextBox
End If

Select Case sText
    Case "Not Available"
          Me.txtYourTextBox.ForeColor = vbRed
    Case "Some other value"
          Me.txtYourTextBox.ForeColor = vbGreen
    Case ...
End Select

Did that help any? You will need to copy and paste this to the On Current event, and the Before Insert and Before Update events on the form.

mmcdonal
Reply With Quote
  #4 (permalink)  
Old May 11th, 2007, 10:05 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

If this is for a report, put the code in the On Format event for whatever section the text box is in, like the Group Header or Detail section.

mmcdonal
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Change An Objects Properties Via Sub Routine Rood67 Access 6 October 12th, 2007 12:14 PM
Change the properties of a textbox control? marksartwork ASP.NET 1.0 and 1.1 Basics 7 April 4th, 2006 04:55 PM
to save forms' properties vubinhsg BOOK: Access 2003 VBA Programmer's Reference 1 December 20th, 2004 06:20 PM
Changing forms properties at run time Louisa VB.NET 2002/2003 Basics 5 January 15th, 2004 01:07 PM



All times are GMT -4. The time now is 04:25 AM.


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