Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
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 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 December 27th, 2006, 08:06 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default Forms Collection can't find form

I have a set of forms I want to change the backcolor of and the function I wrote is not finding the form within the collection. When I run the function (which is called in the formload and afterupdate of the involved controls) I get an error that says Access cannot find the form (strFormName) referred to. Stepping through the code shows the variable strFormName contains the correct form name. The collection just doesn't like it.

I'm obviously doing something wrong and can't figure it out. Can someone help please?

Thank you,

Loralee
+++++++++++++++++++++++++++++++++++++

Public Function UpdateBackcolor(strFormname As String, lngStatusid As Long)
'this function is called by frmPatient and frmReferral to update the backcolor
'based on patients status in PCG Program


    If lngStatusid = 3 Then
        Forms!strFormname.Detail.BackColor = conClosedColor
    Else
        Forms!strFormname.Detail.BackColor = conOpenColor
    End If


End Function

 
Old December 28th, 2006, 11:03 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Access can't "find" a form unless it is open. Perhaps if you moved the code to another event?
Try the code on the On Current Event of the form that is open.

mmcdonal
 
Old December 28th, 2006, 12:14 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default

On Current and On Activate both failed with the same message. Yet when I step through the correct form name is in strformname. I even tried changing it to a sub (as am not returning a value) and that didn't change it any. May take the function down to a form level one for each form if needed, but would prefer to be able to do it once globally.

 
Old December 28th, 2006, 12:17 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

How about this on the form's On Current Event:

If lngStatusid = 3 Then
        Me.Detail.BackColor = conClosedColor
    Else
        Me.Detail.BackColor = conOpenColor
    End If


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the collection of forms ramesh_cnj .NET Framework 1.x 0 February 27th, 2006 08:47 AM
Sending Form Collection To *base.cs file bsausser ASP.NET 1.0 and 1.1 Basics 11 February 12th, 2004 03:42 PM
Cannot find this book . ASP.NET Web Forms redcao All Other Wrox Books 1 October 14th, 2003 02:07 AM
Data collection form prob. d.mx/mysql €urorunner Dreamweaver (all versions) 4 September 24th, 2003 05:42 AM





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