473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Run a Module (Public Function) from a detail report event procedure

Hi,

Instead of repeating the code in multiple reports, i wanted to create a module that will be called for all types of reports that i have created.

The code that I plan to execute is a Public function under Module1, and being called from "on format" event procedure of my detail reports. The code below is typical for the rest of my 10 reports.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  4.  
  5. F14.BackStyle = 1
  6.  
  7.    If Text35 = "A" Then
  8.       F14.BackColor = RGB(0, 128, 128)
  9.       F14.ForeColor = vbWhite
  10.  
  11.  
  12.    ElseIf Text35 = "B" Then
  13.       F14.BackColor = RGB(255, 102, 0)
  14.       F14.ForeColor = vbBlack
  15.  
  16.    ElseIf Text35 = "C" Then
  17.       F14.BackColor = RGB(204, 204, 255)
  18.       F14.ForeColor = vbBlack
  19.  
  20.  
  21.    Else
  22.       F14.BackColor = vbWhite
  23.       F14.ForeColor = vbBlack
  24.  
  25.  
  26.    End If
  27.  
  28. End Sub

Goal should be like this..

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) 
  2.  
  3. Call Module1 
  4.  
  5. End Sub
Please help thank you.
Nov 26 '15 #1
1 929
NeoPa
32,556 Expert Mod 16PB
As a first thing I'd say check out Require Variable Declaration. Running without that set, as you are, is a recipe for disaster.

AJLJ:
Goal should be like this.
Not really. That makes little sense. However, it could be like :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2.     Call ColourX(objVar:=F14, strVar:=Me.Text35.Value)
  3. End Sub
This is complicated by the lack of any explanation of what F14 and Text55 are and where they come from. The example code below will certainly be less useful due to the lack of that information.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Sub ColourX(objVar As Object, strVar As String)
  5.     With objVar
  6.         .BackStyle = 1       'Normal
  7.  
  8.         Select Case strVar
  9.         Case "A"
  10.             .BackColor = RGB(0, 128, 128)
  11.             .ForeColor = vbWhite
  12.         Case "B"
  13.             .BackColor = RGB(255, 102, 0)
  14.             .ForeColor = vbBlack
  15.         Case "C"
  16.             .BackColor = RGB(204, 205, 255)
  17.             .ForeColor = vbBlack
  18.         Case Else
  19.             .BackColor = vbWhite
  20.             .ForeColor = vbBlack
  21.         End Select
  22.     End With
  23. End Sub
Nov 26 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chris B. | last post by:
I'm getting some strange results in an asp.net web application that has recently gone live. In the header of almost all the pages, the full name of the currently logged in user is displayed. On...
3
by: Jason | last post by:
I have an ASP.NET application in which I would like to call my button click event (imgSubmitSearch_Click) on the page load if certain criteria are met. Is this possible? What is the correct...
1
by: Robert | last post by:
Every thing worked fine until all of a sudden, I get the following error whenever I try to do anything on one of my forms that calls an Event Procedure. I get the error as soon as the form opens...
1
by: peter shaw | last post by:
Hi, I got an error message after I created a new event procedure for a grid control. But I can write a new procedure without any problem. The error is...
5
by: MLH | last post by:
None of my applications' many forms have actions defined for the Form_Close event. I would lke to automate the addition of the following procedure to all my forms in their Close Event property...
1
by: vbisjustforme | last post by:
Hello, I am working on a windows dll and this is my problem: 'api Public Declare Function myFunction Lib "Functionmine.dll" (byval ProgieName as String) as Boolean 'entry point in module...
1
by: AMD_GAMER | last post by:
Hi, I am trying to print address labels. I have a form which asks for the user to input the first name, middle initial, and last name. On the button click to print the label, I have an event...
8
gnawoncents
by: gnawoncents | last post by:
I have a dynamic report (created from VBA coding) and I want to set the OnClose event procedure to make another form visible when the report closes. I cannot access the events in the report itself...
3
Knut Ole
by: Knut Ole | last post by:
i get the following error: "The expression On Mouse Move you entered as the event property setting produced the following error: A problem occurred while Access was communicating with the OLE server...
8
by: RojK | last post by:
Hi, I have a userform which has some command buttons and multiple listboxes in VBA. I have a class module which handles events on the form, and a code in the form's initialization section which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.