Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What is the syntax to reference Access report fields in VBA

Posted on 2009-07-06
5
Medium Priority
?
643 Views
Last Modified: 2013-11-28
I am trying to call an Access report field from a Macro but can't seem to get the syntax correct in my VBA script. I have enclosed a copy of my code. This may look a little muddled as I have tried several attempts to get it to work.

Hopefully from the code it should be quite obvious what I am trying to do, update the rag report output to appropriate colours so that I can then export the file. (which conditional formatting doesn't allow.


DoCmd.openreport "rpt90", acViewPreview
 
Dim rpt90 As Report_rpt90
 
If rpt90!RAG_Label = "A" Then
Rrpt90.RAG_Label.Properties("ForeColor") = vbYellow
ElseIf Reports!rpt90.TextBox("R/A/G") = "R" Then
Reports!rpt90.TextBox("R/A/G").ForeColor = vbRed
ElseIf UCase(Reports!rpt90.TextBox("R/A/G")) = "G" Then
Reports!rpt90.TextBox("R/A/G").TextBox.ForeColor = vbGreen
End If
 
End Sub

Open in new window

0
Comment
Question by:JayceW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 24785180
Here are a few comments:

<If rpt90!RAG_Label = "A" Then>

If RAG_Label is a label (not a textbox) then you need to use the Caption property (otherwise the syntax is fine as-is):

If rpt90!RAG_Label.Caption = "A" Then

<Rrpt90.RAG_Label.Properties("ForeColor") = vbYellow>
Is simply:
Rrpt90.RAG_Label.Properties.ForeColor = vbYellow

<ElseIf Reports!rpt90.TextBox("R/A/G") = "R" Then>
is "R/A/G" the name of your textbox?  If so, consider renaming it using standard naming convetions which avoid spaces and special characters, for example txtRAG.

Otherwise, use Brackets and the following syntax:

ElseIf Reports!rpt90.[R/A/G] = "R" Then

The same thing applies to all your other references to R/A/G.
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 500 total points
ID: 24785202
The Reddick VBA Naming conventions are described here:
http://www.xoc.net/standards/rvbanc.asp

Conventions specific to Access are midway down the page.

Most of the regulars here follow these conventions.
0
 

Author Closing Comment

by:JayceW
ID: 31600135
Excellent thanks, Next step I will find out how to loop through the rows on my report to apply the formatting.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24785976
JayceW,

I think mbizup has most of this covered, but, ...
What is this line supposed to ber doing?:
    Dim rpt90 As Report_rpt90

AFAICT (Unless you have some special Library loaded), your code will error out right away at this line, with a "User defined type, not defined" error.

Perhaps it should be:
    Dim rpt90 As Report

?

JeffCoachman
0
 

Author Comment

by:JayceW
ID: 24786014
Thanks Jeff, that line, as you suggest was not needed, so I have already removed it from the code
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question