473,385 Members | 1,869 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,385 software developers and data experts.

Accessing Current Record within On Format

Hi,

Stupid question of someone just starting to program in VBA.

I just want to access the current record in a report within the On Format event so that I can dynamically create various variables based on data stored in a database. I, however, don't have a clue how to reference the data and everything I try results in Run time error '2465: Microsoft Access can't find the field errors.

Is there a tutorial out there that answers this, what seems like, simple question?

I've tried me.[field_name], the field name, etc.

Thanks.
Nov 12 '08 #1
7 4750
ADezii
8,834 Expert 8TB
Just a general response, to access data in every Record in a report, then make decisions based on that data, you could use code similar to the following:
Expand|Select|Wrap|Line Numbers
  1. If Me![Date_Due] >= Date Then
  2.   Me![txtStatus] = "Overdue"
  3. Else
  4.   Me![txtStatus] = "On Time"
  5. End If
P.S. - Depending on your circumstances, you may be better off using the Detail Section's Print() Event as opposed to the Format() Event.
Nov 12 '08 #2
Just a general response, to access data in every Record in a report, then make decisions based on that data, you could use code similar to the following:
Expand|Select|Wrap|Line Numbers
  1. If Me![Date_Due] >= Date Then
  2.   Me![txtStatus] = "Overdue"
  3. Else
  4.   Me![txtStatus] = "On Time"
  5. End If
P.S. - Depending on your circumstances, you may be better off using the Detail Section's Print() Event as opposed to the Format() Event.

Thanks.

Is the only mistake I was making that I was using a period as opposed to an !? Or is there something else I need to do to make the record visible within the on format event?
Nov 12 '08 #3
ADezii
8,834 Expert 8TB
Thanks.

Is the only mistake I was making that I was using a period as opposed to an !? Or is there something else I need to do to make the record visible within the on format event?
You can also use a period, if you like.
Nov 12 '08 #4
Stewart Ross
2,545 Expert Mod 2GB
Hi. As ADezii's reply shows, accessing the controls on your report is straightforward. From what you have written it would appear that the cause may lie elsewhere. One possibility is that you may be trying to access a field in the underlying recordset for that report which does not have a matching control of that name on the report, or trying to access a field from another table which is not part of the report's recordset.

What Me.yourcontrolname means is "the value of control 'yourcontrolname' located on the current report". It does not mean the value of field X, where X is a field that has no matching control on the report.

You will see a list of the controls on your report as you type if you use the period notation - for instance, typing me.m in the VB editor will show all the objects (including controls) beginning with the letter m that you can access. Access will replace any spaces in the names with underscores, like this

me.a_control_name_with_spaces

I'd suggest you check that the control you are trying to access actually exists simply by trying the matching I have suggested. If it doesn't all you need to do is to drag the name of the field from the field list onto your report to create a textbox control for that field on your report (assuming that the field does exist in your report's recordsource query).

If the control really does exist and you are getting such errors I am not at all certain what more to suggest. Perhaps if that happens you could post the code you are trying to use so we can look at what may be going wrong.

-Stewart
Nov 12 '08 #5
Thanks everyone.

I must have mess something else up as I completely started over and now I can see the fields.

Thanks.
Nov 12 '08 #6
I spoke too fast.

My problem has reemerged.

Here is the very simple code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Dim banner As String

If Me.TAGed = Yes Then
banner = "Foo"
Else
banner = "Bar"
End If

Me.TestText = banner


End Sub


It works for some of the fields within the result set, but, others it says it can't locate the variable.

It autocompletes with any of the fields within the field list, and, all of the fields show up in the field list. Do I need to drop some hidden control for every field in other to access it? Or, is there a way I can directly access the returned field?
Nov 12 '08 #7
Stewart Ross
2,545 Expert Mod 2GB
Hi. Problem is that you are trying to compare the value of TAGed to a constant called Yes - which simply does not exist in VBA. This results in the error you are experiencing about missing variables.

If TAGed is a Boolean value (one which is defined in the underlying table as a Yes/No field) its values can be -1 (represented by the constant True) or 0 (represented by the constant False.

You can test its value in a number of ways, all equivalent:

Expand|Select|Wrap|Line Numbers
  1. If Me.TAGed = True Then X Else Y
  2. If Me.TAGed = -1 Then X Else Y
  3. If Me.TAGed Then X Else Y
It is the last of these I would recommend to you, as it is redundant to check a value of True or False against the constant True.

-Stewart
Nov 13 '08 #8

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

Similar topics

14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
4
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I...
4
by: Mullin Yu | last post by:
i have a stored procedure at sql server 2k. which will update records and select result from temp table. if i use SqlConnection class, and i do both. but, if i use OleDbConnection class, i can...
3
by: Jim Lewis | last post by:
I have read several things that state accessing a Web Service through a Query String should work. However, when I try to execute http://localhost/webservice1/service1.asmx/HelloWorld I get the...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
1
by: omantawy | last post by:
Hi, I have some legacy ASP web applications that use an unmanaged COM component to connect to a third party application. The third part application has moved to the managed code in the current...
3
by: Kosmos | last post by:
Hey ya'll...I can't seem to figure out why I'm getting this error message, but it all started when I added the new line of code with the recSet5.AddNew --- when I ran the first line, the logic worked...
1
by: senort01 | last post by:
This question got lost on the bottom of another thread. Is it the case that you can't access specific fields of a record set without placing a control that's linked to that record on the report? ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.