473,385 Members | 2,004 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.

stLinkCriteria

12
I have a MS Access database made over ten years back and slowly improved through the year. Now I am attempting to improve also the reporting. For instance, I need to summarize the expenses paid to a specific beneficiary but can't make it work. With the coding below it's opening the document with the full data and not the selected one.

FYI I am opening the report from a form where I can select input a specific text and would like to show only data matching the same.

Any suggestion?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_Report_Click()
  2. On Error GoTo Err_Open_Report_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "RAKC1_CPR_REPORT_BENEFICIARY"
  7.     DoCmd.OpenReport stDocName, acViewReport
  8.  
  9.     stLinkCriteria = "Me![beneficiary]=" & [beneficiary]
  10.  
  11.  
  12. Exit_Open_Report_Click:
  13.     Exit Sub
  14.  
  15. Err_Open_Report_Click:
  16.     MsgBox Err.description
  17.     Resume Exit_Open_Report_Click
  18.  
  19. End Sub
Feb 11 '19 #1

✓ answered by Seth Schrock

Good catch on adding the quotes to the criteria string. I should have checked on that myself.

On adding a second criteria...
A variable only contains what it is assigned. It doesn't get added to. Seems simple, but look again at lines 7 and 8. On line 7, you assign a value to stLinkCriteria. On line 8, you assign another value to stLinkCriteria, wiping out the previous value from line 7. This can be done by concatenating the value of stLinkCriteria with another value and assigning that back to stLinkCriteria.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = stLinkCriteria & " And [project]=" & "'" & Me![project] & "'"
Notice the And I put before [project]. That is how you have multiple criteria in a SQL WHERE statement (which is what you are building minus the word WHERE).

However, in this case you can just do it all on one line.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[beneficiary]=" & "'" & Me![beneficiary] & "' And [project]=" & "'" & Me![project] & "'"
if you want the line shorter, then use a line continuation character and then make a new line.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[beneficiary]=" & "'" & Me![beneficiary] & _
  2.                  "' And [project]=" & "'" & Me![project] & "'"
One quick note about posting questions, we only allow one question per thread. This one was kind of one the edge of being a new question, but about the same problem so I did answer it here. Just for future reference, try to keep each thread on one focus. New questions can be posted in a new thread. It makes it easier for answers to be found in a search.

4 3316
Seth Schrock
2,965 Expert 2GB
There are a couple problems. First, your criteria isn't formatted correctly. Assuming that the Me!beneficiary control is bound to a field named beneficiary. If that is correct, then change stLinkCriteria to stLinkCriteria = "[beneficiary]=" & Me![beneficiary].

Second problem is that your criteria isn't ever applied. Move line 9 above 7 and then change 7 to
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport ReportName:=stDocName, View:=acViewReport, WhereCondition:=stLinkCriteria
Give that a try and let us know.
Feb 11 '19 #2
nsiotto
12
Seth thanks for your input. While waiting the answer actually I managed to get it right.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_Report_Click()
  2.  
  3.     Dim stDocName As String
  4.     Dim stLinkCriteria As String
  5.  
  6.     stDocName = "RAKC1_CPR_REPORT_BENEFICIARY"
  7.  
  8.     stLinkCriteria = "[beneficiary]=" & "'" & Me![beneficiary] & "'"
  9.  
  10.     DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
  11.  
  12. End Sub
  13.  
It works fine now (guess there are various variable to obtain the same). However now I have another issue. I need to select two criteria and not just one.

I did the following but it takes only one:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_Report_Click()
  2.  
  3.     Dim stDocName As String
  4.     Dim stLinkCriteria As String
  5.  
  6.     stDocName = "RAKC1_CPR_REPORT_BENEFICIARY"
  7.     stLinkCriteria = "[beneficiary]=" & "'" & Me![beneficiary] & "'"
  8.     stLinkCriteria = "[project]=" & "'" & Me![project] & "'"
  9.  
  10.     DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
  11.  
  12. End Sub
  13.  
I know that I am missing a stupid elementary mistake but maybe I could get it faster with your help. Thanks.
Feb 11 '19 #3
Seth Schrock
2,965 Expert 2GB
Good catch on adding the quotes to the criteria string. I should have checked on that myself.

On adding a second criteria...
A variable only contains what it is assigned. It doesn't get added to. Seems simple, but look again at lines 7 and 8. On line 7, you assign a value to stLinkCriteria. On line 8, you assign another value to stLinkCriteria, wiping out the previous value from line 7. This can be done by concatenating the value of stLinkCriteria with another value and assigning that back to stLinkCriteria.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = stLinkCriteria & " And [project]=" & "'" & Me![project] & "'"
Notice the And I put before [project]. That is how you have multiple criteria in a SQL WHERE statement (which is what you are building minus the word WHERE).

However, in this case you can just do it all on one line.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[beneficiary]=" & "'" & Me![beneficiary] & "' And [project]=" & "'" & Me![project] & "'"
if you want the line shorter, then use a line continuation character and then make a new line.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[beneficiary]=" & "'" & Me![beneficiary] & _
  2.                  "' And [project]=" & "'" & Me![project] & "'"
One quick note about posting questions, we only allow one question per thread. This one was kind of one the edge of being a new question, but about the same problem so I did answer it here. Just for future reference, try to keep each thread on one focus. New questions can be posted in a new thread. It makes it easier for answers to be found in a search.
Feb 11 '19 #4
nsiotto
12
Works! Thanks a million Seth!
Feb 11 '19 #5

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

Similar topics

1
by: universal | last post by:
Hello all, Iam a complete beginner, so please be gentle. Im trying to (if possible) create a form to be used as a "search" facility of another form. All users list their favourite foods:...
8
by: Abby B via AccessMonster.com | last post by:
Hi, I modified a code for a search form to open a form for a specific criteria as one of the search fields was not working. Now it works but the problem is I get the Enter Parameter pop up for...
1
by: brittonsm | last post by:
I have a form with a button, now when I click the button it uses one combo box to filter a new form that the button opens. What I need to do is have the form filter by two of the combo boxes on...
0
by: cwm137 | last post by:
I have a form named "Customer Search" with a subform called "Cust Search Subform" that contains summary data about every order a customer has made. I would like to be able to select a single order...
3
by: chucher | last post by:
I'm trying to put a filter into some forms or filters but the filter donīt work properly. I'm using the format dd-mm-yyyy. The forms and the tables always shows how dates in that format. But...
3
by: ruthboaz | last post by:
Hi, I have a numeric Field RFINo and a Yes/No Data type for Issued stLinkCriteria = " = " & lstRFINo.Value & " And = Yes" With the above I am not getting the specific record. Pls advice.
2
by: mark mestrom | last post by:
hi, i have this problem with OpenForm and the stLinkCriteria. I have the following code: Private Sub Knop22_Click() On Error GoTo Err_Knop22_Click Dim stDocName As String Dim...
5
by: NHAnimator | last post by:
Hello, I have the following script which I need to modify: Private Sub Command231_Click() On Error GoTo Err_Command231_Click Dim stDocName As String Dim stLinkCriteria As String
4
by: crazyhouse | last post by:
This is the line of code i am trying to use. It doesnt work. I want the form to open only records that match the inspectjn, and accqty isnull. inspectjn is text accqty is a number ...
2
by: JpjVB | last post by:
Hi, I have a filtered form that produces a set of employee names that are hyperlinks. When clicked, the EmployeeName hyperlink opens another form called Budgeted Time. I would like to filter the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.