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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Module to Service Multiple Forms



 
 
Thread Tools Display Modes
  #1  
Old September 21st, 2006, 09:48 PM posted to microsoft.public.access.forms
Alan
external usenet poster
 
Posts: 459
Default Module to Service Multiple Forms

This is hopefully a simple question.

I have a Sub Routine that I was given a bit of help with previously that
updates a number of captions on any form, details of which are stored in
tblControlSQL

Public Sub UpdateFormInfo(strDataSet As String)

Dim rstData As Recordset
Dim CtrlSource As Control

strSQL = "SELECT * FROM tblControlSQL WHERE (((tblControlSQL.DATASET)='" &
strDataSet & "') AND ((tblControlSQL.Type)='Button'))"
Set rstData = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

While rstData.EOF = False
With rstData
Set CtrlSource = Forms!UpdateData.Controls(.Fields("Name"))
CtrlSource.Caption = .Fields("CountRowsValue")
If CtrlSource.Caption = 0 Then
CtrlSource.ForeColor = 32768
ElseIf CtrlSource.Caption = "N/A" Then
ctl.ForeColor = vbBlack
Else: CtrlSource.ForeColor = vbRed
End If

.MoveNext
End With
Wend
End Sub

I can now see a use for reusing this code and would like it to work on other
Forms other than 'Forms!UpdateData'... can anyone point me in the right
direction of having a Forms variable ???

I have tried changing the sub to UpdateFormInfo(strDataSet As String,
FormName as Form) however continually get errors.

Any help would be gratefully appreciated

Regards
  #2  
Old September 21st, 2006, 10:13 PM posted to microsoft.public.access.forms
Barry Gilbert
external usenet poster
 
Posts: 379
Default Module to Service Multiple Forms

Instead of passing in a form object, pass in the name of the form:
UpdateFormInfo(strDataSet As String, ByVal strFormName as String)

Then refer to it like this:
CurrentProject.AllForms(strFormName)

Barry

"Alan" wrote:

This is hopefully a simple question.

I have a Sub Routine that I was given a bit of help with previously that
updates a number of captions on any form, details of which are stored in
tblControlSQL

Public Sub UpdateFormInfo(strDataSet As String)

Dim rstData As Recordset
Dim CtrlSource As Control

strSQL = "SELECT * FROM tblControlSQL WHERE (((tblControlSQL.DATASET)='" &
strDataSet & "') AND ((tblControlSQL.Type)='Button'))"
Set rstData = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

While rstData.EOF = False
With rstData
Set CtrlSource = Forms!UpdateData.Controls(.Fields("Name"))
CtrlSource.Caption = .Fields("CountRowsValue")
If CtrlSource.Caption = 0 Then
CtrlSource.ForeColor = 32768
ElseIf CtrlSource.Caption = "N/A" Then
ctl.ForeColor = vbBlack
Else: CtrlSource.ForeColor = vbRed
End If

.MoveNext
End With
Wend
End Sub

I can now see a use for reusing this code and would like it to work on other
Forms other than 'Forms!UpdateData'... can anyone point me in the right
direction of having a Forms variable ???

I have tried changing the sub to UpdateFormInfo(strDataSet As String,
FormName as Form) however continually get errors.

Any help would be gratefully appreciated

Regards

  #3  
Old September 24th, 2006, 09:20 AM posted to microsoft.public.access.forms
Peter R. Fletcher
external usenet poster
 
Posts: 32
Default Module to Service Multiple Forms

Alternatively, and possibly more conveniently, pass the Form as an
object (Me in the calling routine), and refer to the name in the Sub
as a Property of the passed Form. Using your Sub declaration, the
Form's _name_ would be FormName.Name.


On Thu, 21 Sep 2006 14:13:02 -0700, Barry Gilbert
wrote:

Instead of passing in a form object, pass in the name of the form:
UpdateFormInfo(strDataSet As String, ByVal strFormName as String)

Then refer to it like this:
CurrentProject.AllForms(strFormName)

Barry

"Alan" wrote:

This is hopefully a simple question.

I have a Sub Routine that I was given a bit of help with previously that
updates a number of captions on any form, details of which are stored in
tblControlSQL

Public Sub UpdateFormInfo(strDataSet As String)

Dim rstData As Recordset
Dim CtrlSource As Control

strSQL = "SELECT * FROM tblControlSQL WHERE (((tblControlSQL.DATASET)='" &
strDataSet & "') AND ((tblControlSQL.Type)='Button'))"
Set rstData = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

While rstData.EOF = False
With rstData
Set CtrlSource = Forms!UpdateData.Controls(.Fields("Name"))
CtrlSource.Caption = .Fields("CountRowsValue")
If CtrlSource.Caption = 0 Then
CtrlSource.ForeColor = 32768
ElseIf CtrlSource.Caption = "N/A" Then
ctl.ForeColor = vbBlack
Else: CtrlSource.ForeColor = vbRed
End If

.MoveNext
End With
Wend
End Sub

I can now see a use for reusing this code and would like it to work on other
Forms other than 'Forms!UpdateData'... can anyone point me in the right
direction of having a Forms variable ???

I have tried changing the sub to UpdateFormInfo(strDataSet As String,
FormName as Form) however continually get errors.

Any help would be gratefully appreciated

Regards


Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 




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


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