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

Need help creating Access Report in VBA

4
I am generating a student transcipt report initiated from a VBA Menu screen. The user clicks a menue option to generate a student transcript. The vba code asks the user to enter the student ID. The vba gets the user ID, verifies the student is in the database. I have preset Report (form) already created with Report header information, labels and textbox for student ID, Name, Courses taken, etc. This portion I have already done.

Here is where I am struggling: I want the vba code to pass the student ID to the Access Report form or it's query and it would use the ID to search a "Courses-Taken" table and if the student has completed at least one course, it would generate the student's transcript report. How to pass the student ID to the Report form or its underlying query is where my problem is.

Any help would be appreciated.

Thanks,
Nzaae
Jun 23 '14 #1
10 1215
twinnyfo
3,653 Expert Mod 2GB
Nzaaev,

Create a SQL string that uses the Query for the Report's record source and use the Student ID as the criteria for the query. Then set the report's record Source to that Query. That should do the trick.
Jun 23 '14 #2
NeoPa
32,556 Expert Mod 16PB
It's even easier than that.
  1. Design the report (or more precisely the underlying query) to get all the information required from any relevant tables for all students.
  2. When opening the report specify a filter string for the selected student.
Jun 23 '14 #3
Nzaaev
4
Thanks for the response. However, here is where my hangup is:
SELECT StudID
FROM StudTable
WHERE StudID = SID;

(1) How do I pass the variable SID to this query from my VBA code?
(2) StudTable has more than one column. Iam getting a prompt to enter values for the other columns which I do not need and did not specify in my Select statement. How do I specify to select only one column so I do not get the prompt?

Thanks, again. I am new to VBA
Jun 23 '14 #4
NeoPa
32,556 Expert Mod 16PB
It's not clear from your post which post you're referring to. It doesn't make good sense for either from what I can see.

If you're taking Twinny's approach then the SQL created has a literal value set where you refer to SID.

If you take my approach then it's even easier. You start with a working query that exposes [StudID] and apply the filter with the DoCmd.OpenReport() call.
Jun 24 '14 #5
twinnyfo
3,653 Expert Mod 2GB
Nzaaev,

Using NeoPa's (better) advice,

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "YourReportName", , "[StudID] = " & [SID]
However, I am concerned about the actual language you use in your questions, and the term "Report" seems to be freely interchanged with the term "Form" (see post #1).

Is this a "Report" or a "Form" that is reporting data?
Jun 24 '14 #6
Nzaaev
4
Ok. Let me try it again.
The menu selection the user clicked was to generate a transcript for a student. The VBA code prompts the user to enter the ID (SID) of the user to which a transcript is to be generated. The user enters the student ID (SID variable) in the VBA code. Then my VBA code is to pass this SID to the SQL query to be used as the search criteria in my WHERE clause. I used Access Report Wizard to design the Report. The SQL query is already defined as the Record Source for the Report.

Therefore, the user selects the request to generate student transcript, the vba code prompts the user for the student ID; the user enters the student ID in a text box window; the vba code verifies the ID and then passes the ID (SID variable) to the query; the query executes and generates the transcript reportand displays it Report View.

So how do I pass the SID from the VBA Code to the Query?

Hope this is clearer.

Thanks,
Jun 24 '14 #7
twinnyfo
3,653 Expert Mod 2GB
Post #6 describes exactly what to do. You do not send the SID to the Query, you filter the report based on the SID.
Jun 24 '14 #8
Nzaaev
4
twinnyfo,
I implemented post #6 as suggested. Below is the Docmd statement:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "Transcript-Report", acViewPreview, , "[Stud_ID] = " & [SID]
But I am getting the following error code with message:

Run time error "3071":

"The expression is typed incorrectly, or it is too
complex to be evaluated. For example, a numeric
expression may contain too many complicated elements.
Try simplifying the expression by assigning parts of
the expression to variables".

The variable SID is type String in my VBA code, and Stud_ID is the field in my table of type Text.

What amy I doing wrong?

Thanks,
Jun 24 '14 #9
NeoPa
32,556 Expert Mod 16PB
Firstly, it's important that you read and follow the instructions in Debugging in VBA. So much time and effort is wasted dealing with stupid errors that should never come up, but do because people don't get even the basics right.

I would guess that this is the result of a run-time error due to referring to your variable (SID) within brackets ([]).

If not, then it's likely that it's because you don't have a working query for the report in the first place.

First ensure your code compiles properly with :
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
When that's done test out the report with NO filtering. This is the point you should be at before you even start thinking about the filter. If that all works but the filtering doesn't then it's a good time to look at the filtering. At that point it should be very simple and there will be nothing else to confuse matters unnecessarily.
Jun 24 '14 #10
NeoPa
32,556 Expert Mod 16PB
It may also help to get your head around what you're doing by reading this amended version of your statement of intent from post #7 :
The menu selection the user clicked was to generate a transcript for a student. The VBA code prompts the user to enter the ID (SID) of the user to which a transcript is to be generated. The user enters the student ID (SID variable) in the VBA code. Then my VBA code is to pass this SID to the SQL query to be used as the search criteria in my WHERE clause. the report is opened to show just the transcript for that selected student. I used Access Report Wizard to design the Report. The SQL query is already defined as the Record Source for the Report.
The underlined text should be replaced by the italicised text.
Jun 24 '14 #11

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

Similar topics

1
by: El_Embozador | last post by:
Hi , please can you tell how i can print an MS ACCESS Report form visual basic, i ned a sample code .. Thanks
15
by: Mark C | last post by:
All, I have exhaustingly been looking through the newsgroups in search of a way to systemically output an Access 97 report to a pdf file using the full version of Adobe Acrobat. I want the user...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
7
by: msrado | last post by:
Hi All, I have a report in Microsoft Access 2000 that appears with standard blank font in a print preview and shaded grey font in a printout. I don't want it to be shaded and can't figure out...
5
by: John | last post by:
I have 2 tables, one with dates and information about those dates, and one with people information. I want to create a report listing each date and the people who attended on that date (who have...
1
by: ellenh | last post by:
I have read postings on the similar subject including the posting from 2003 shown below. This process works fine to display a single page snapshot report in PowerPoint. I need to display...
2
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still...
1
by: ITTrimbleKY | last post by:
Issue: I am creating a report that I want running sums in. The problem is that the field I am summing has 3 different entries that I need to sum. I have tried doing the IIF statement, but it doesn't...
7
by: olseni | last post by:
Hi all I hope someone can help me with this. I am sure there is a solution, but I cannot seem to find it.... I need to make a report with the following format: In the columns I have 5 samples,...
1
by: sjivanjee | last post by:
I have two table one stores student information and other one is for their attendance. In the attendance table their is a field called Attendance Status which has a value of P,A,Ex or L and Block...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.