473,468 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need help creating Access Report in VBA

4 New Member
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 1216
twinnyfo
3,653 Recognized Expert Moderator Specialist
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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 Recognized Expert Moderator Specialist
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 New Member
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 Recognized Expert Moderator Specialist
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 New Member
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 Recognized Expert Moderator MVP
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 Recognized Expert Moderator MVP
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
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
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...
1
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
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.