Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2007, 08:39 AM
Authorized User
 
Join Date: Jan 2007
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


 
Old May 11th, 2007, 09:00 AM
Authorized User
 
Join Date: Jan 2007
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

 
Old May 11th, 2007, 10:03 AM
Friend of Wrox
 
Join Date: Mar 2004
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
 
Old May 11th, 2007, 10:05 AM
Friend of Wrox
 
Join Date: Mar 2004
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





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





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