I want to shorten my codes coz i got a compile error: procedure too large. is there a way that these thing can be done in shortest code?
this are my sample codes: i have a hundred of this codes, i only pasted 12 to show you. - If Form_List.RecordSource = ("calvelo joseph Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "calvelo joseph Query"
-
Reports("Clearance").RecordSource = ("calvelo joseph Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "calvelo joseph Query"
-
Else
-
If Form_List.RecordSource = ("carpio godofredo Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "carpio godofredo Query"
-
Reports("Clearance").RecordSource = ("carpio godofredo Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "carpio godofredo Query"
-
Else
-
If Form_List.RecordSource = ("caseros roberto Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "caseros roberto Query"
-
Reports("Clearance").RecordSource = ("caseros roberto Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "caseros roberto Query"
-
Else
-
If Form_List.RecordSource = ("celajes artemio Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "celajes artemio Query"
-
Reports("Clearance").RecordSource = ("celajes artemio Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "celajes artemio Query"
-
Else
-
If Form_List.RecordSource = ("coloma lino Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "coloma lino Query"
-
Reports("Clearance").RecordSource = ("coloma lino Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "coloma lino Query"
-
Else
-
If Form_List.RecordSource = ("dayao jose Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "dayao jose Query"
-
Reports("Clearance").RecordSource = ("dayao jose Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "dayao jose Query"
-
Else
-
If Form_List.RecordSource = ("De Guzman josian Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "De Guzman josian Query"
-
Reports("Clearance").RecordSource = ("De Guzman josian Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "De Guzman josian Query"
-
Else
-
If Form_List.RecordSource = ("De Guzman vernadette Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "De Guzman vernadette Query"
-
Reports("Clearance").RecordSource = ("De Guzman vernadette Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "De Guzman vernadette Query"
-
Else
-
If Form_List.RecordSource = ("Dela Cruz helen Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "Dela Cruz helen Query"
-
Reports("Clearance").RecordSource = ("Dela Cruz helen Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "Dela Cruz helen Query"
-
Else
-
If Form_List.RecordSource = ("donsol elvira Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "donsol elvira Query"
-
Reports("Clearance").RecordSource = ("donsol elvira Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "donsol elvira Query"
-
Else
-
If Form_List.RecordSource = ("Dorosan jan christopher Query") Then
-
DoCmd.OpenReport "Clearance", acViewDesign, "Dorosan jan christopher Query"
-
Reports("Clearance").RecordSource = ("Dorosan jan christopher Query")
-
DoCmd.OpenReport "Clearance", acViewPreview, "Dorosan jan christopher Query"
-
end if
-
end if
-
end if
-
end if
-
end if
-
end if
-
end if
-
end if
-
end if
-
end if
-
end if
-
end if
-
end sub
Well there is alot to say about the code you have shown.
First of, from what I see, it seems your if/then/else statements in the shown code are superflous, you could simply write it as: - Dim strSource as String
-
strSource=Form_List.RecordSource
-
DoCmd.OpenReport "Clearance", acViewDesign, strSource
-
Reports("Clearance").RecordSource = strSource
-
DoCmd.OpenReport "Clearance", acViewPreview, strSource
-
Secondly, if you have a limited number of statements you can use the elseIF instead of nested If's. - If X=0 then
-
Msgbox "Divide by zero"
-
elseIf X=2 Then
-
Msgbox X & " is invalid"
-
else
-
Msgbox X
-
end if
Now the above is actually something you should have been able to find out yourself, by simply placing the cursor on the if keyword, and pressing F1, and you would get a nice explanation.
The third option, is the SELECT CASE statement, again, look at the help file for info, but here is an example: - Public Sub DoAction(strAction as string)
-
Select Case strAction
-
Case "Open"
-
DoCmd.OpenForm "frm_Example"
-
Case "Close"
-
Docmd.Close acForm, "frm_Example"
-
case else
-
MsgBox "An invalid argument was passed to the DoAction command"
-
End Select
-
End Sub
10 2630
Well there is alot to say about the code you have shown.
First of, from what I see, it seems your if/then/else statements in the shown code are superflous, you could simply write it as: - Dim strSource as String
-
strSource=Form_List.RecordSource
-
DoCmd.OpenReport "Clearance", acViewDesign, strSource
-
Reports("Clearance").RecordSource = strSource
-
DoCmd.OpenReport "Clearance", acViewPreview, strSource
-
Secondly, if you have a limited number of statements you can use the elseIF instead of nested If's. - If X=0 then
-
Msgbox "Divide by zero"
-
elseIf X=2 Then
-
Msgbox X & " is invalid"
-
else
-
Msgbox X
-
end if
Now the above is actually something you should have been able to find out yourself, by simply placing the cursor on the if keyword, and pressing F1, and you would get a nice explanation.
The third option, is the SELECT CASE statement, again, look at the help file for info, but here is an example: - Public Sub DoAction(strAction as string)
-
Select Case strAction
-
Case "Open"
-
DoCmd.OpenForm "frm_Example"
-
Case "Close"
-
Docmd.Close acForm, "frm_Example"
-
case else
-
MsgBox "An invalid argument was passed to the DoAction command"
-
End Select
-
End Sub
Of corse the first piece of code from Smiley can replace all your code.
But may I ask you why you first open your report in design view ?
This line is not necessary in order to view your report: - DoCmd.OpenReport "Clearance", acViewDesign, strSource
So you can remove it making the code even shorter: - Dim strSource as String
-
strSource=Form_List.RecordSource
-
Reports("Clearance").RecordSource = strSource
-
DoCmd.OpenReport "Clearance", acViewPreview, strSource
I think that the Main point that we are missing here is that, in order to dynamically change the Record Source of a Report, we should: - Open the Report in Design Mode and Hidden
- Modify the Record Source of the Report
- Close the Report, Saving the changes
- Open the Report with the modified Record Source
- Dim strReportName As String
-
-
strReportName = "rptEmployees"
-
-
With DoCmd
-
.OpenReport strReportName, acViewDesign, , , acHidden
-
Reports(strReportName).RecordSource = "qryEmployees"
-
.Close acReport, strReportName, acSaveYes
-
.OpenReport strReportName, acViewPreview, , , acWindowNormal
-
End With
P.S. - A Report does not become a Member of the Reports Collection unless it is Opened in some manner.
Thanks for your reply, The code below is where i used strSource, Is this the right application of your given codes TheSmileCoder? If it is correct, it's the same with my codes. If I'm wrong, how can i use your given codes?
Private Sub TxtClearance_Click()
Dim strSource As String
strSource = Form_List.RecordSource
If strSource = ("juan reynulfo Query") Then
DoCmd.OpenReport "Clearance", acViewDesign, "juan reynulfo Query"
Reports("Clearance").RecordSource = ("juan reynulfo Query")
DoCmd.OpenReport "Clearance", acViewPreview, "juan reynulfo Query"
Else
If strSource = ("lacsamana elizabeth Query") Then
DoCmd.OpenReport "Clearance", acViewDesign, "lacsamana elizabeth query"
Reports("Clearance").RecordSource = ("lacsamana elizabeth query")
DoCmd.OpenReport "Clearance", acViewPreview, "lacsamana elizabeth query"
End If
End If
End Sub
No, eneyardi.
Smiley's code has NOT IFs statements.
You only need to add line 1 and 7 around Smiley's code. - Private Sub TxtClearance_Click()
-
Dim strSource as String
-
strSource=Form_List.RecordSource
-
DoCmd.OpenReport "Clearance", acViewDesign, strSource
-
Reports("Clearance").RecordSource = strSource
-
DoCmd.OpenReport "Clearance", acViewPreview, strSource
-
End Sub
The Smiley's five lines will do ALL your job. This five lines are EQUAL to yours 67 lines from your topic post.
Of course, Smiley assume, as a rule, that ALL your queries has the same name as the attached reports.
Example: Your query is named juan reynulfo Query and the attached report is also named juan reynulfo Query.
As long as you follow this "rule" you can add as many queries/reports as you wish and Smiley's five lines will do the job.
How can i apply that five line of smiley without using if, if i want to call other query?
This is what i need to do in my access program. I have main form name (home), in that form i have a combolist which row source contains 500 names of employees, i have another form which form name is (list). this form will show up when i click one of the name of employee in combolist and its recordsource is based on the name of employee i clicked. For example when i click juan reynulfo, the form list will show up and its recordsource will be juan reynulfo query. In form list there is a command button (print), when i click that print button, report will show up which name is (clearance) and its recordsource is juan reynulfo query. If i click other employee, how can i apply smiley codes replacing my codes without using if as you said?
thanks alot guys, thank you smile, thank you mihail, thank you Adezii. it works!
At last ! You understand the Smiley's logic.
More than that, lets see if this presumes are really:
I am almost sure that all your queries are identical. With a slight difference in the criteria: where you have different names.
And you wish to design as many queries as different names you have (500).
If this is the situation, what about if you wish to use your database for the US army's employes or for the China's peoples ?
To do all the job you need only one query. And to pass to the criteria row the correct name before you use the query.
More: If you use only one query is no more need to dynamically change the row source for your form and report. You can set up the row source at design time (to point to that query).
Let us know if this is your situation.
Good luck !
yup, that's my situation, i don't know that theres a way to use only one query. I will post my next question later regarding that.
Once again thank you very much!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Christian Seberino |
last post by:
I am looking at the ELSE home page and trying to figure out if I should
invest the time to learn about the ELSE minor mode for Emacs.
Is there any programmer out there using ELSE that is getting...
|
by: SpiderFly |
last post by:
I have a popup window where a user can select from a list of address
records. When passing the details back to the calling screen i set all
the address fields using code like this:
...
|
by: Steve Litvack |
last post by:
Hello,
I have built an XMLDocument object instance and I get the following string
when I examine the InnerXml property:
<?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
|
by: Alex P |
last post by:
Hi,
i would like to check for a given query (insert, update, delete) if
there is a key or constraint violation which prevents the query from
being executed.
Is such a feature implemented in the...
|
by: scotspie501 |
last post by:
i have perkins EST and looking for key genenrator for a product code can anyone help
|
by: nurikoAnna |
last post by:
how to properly separate sql codes........
I am using &_ as a separator...because it will not suits the visual basic code form...it will skip to the next line that's why I am having trouble in it...
|
by: tms005 |
last post by:
Anyone know how to compile Aix C++ Codes into Window platform?
I have tried to compile my Aix (Version 4.2) C++ Codes using Bloodshed Dev C++ and Microsoft Visual C++ Compiler and I have copied...
|
by: newphpcoder |
last post by:
I change my database from mysql to mssql, so I need to change the connection code in my php. I’m not familiar about the codes using mssql. Now cannot connect to my database.
I used the following:...
|
by: phpuser123 |
last post by:
When I am running the following codes using Eclipse and Netbeans 6.8. I want to see the available COM ports on my computer. When running in Eclipse it is returning me all available COm ports but...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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,...
|
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,...
|
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...
|
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...
| | |