473,405 Members | 2,444 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,405 software developers and data experts.

pass values to query as criteria from form

I have a query that setting date from and date to from form values works:
>=[forms]![E-Report query]![DateFrom] And <=[forms]![E-Report query]![DateTo]

but now I am trying to add another peramiter to pass in adition to above and now it doesn't work, I get a blank table when I run it and when i run the criteria just for State by

Forms![E-Report query]![State] I get a blank form as well,
what I'm trying to do is is set criteria of query with
>=[forms]![E-Report query]![DateFrom] And <=[forms]![E-Report query]![DateTo] And [forms]![E-Report query]![State]
and when i run it I get a blank table
note(the state field on the form is what the [state]value in the table equles

thanks for help in advance
Mar 8 '08 #1
10 3527
I have a query that setting date from and date to from form values works:
>=[forms]![E-Report query]![DateFrom] And <=[forms]![E-Report query]![DateTo]

but now I am trying to add another peramiter to pass in adition to above and now it doesn't work, I get a blank table when I run it and when i run the criteria just for State by

Forms![E-Report query]![State] I get a blank form as well,
what I'm trying to do is is set criteria of query with
>=[forms]![E-Report query]![DateFrom] And <=[forms]![E-Report query]![DateTo] And [forms]![E-Report query]![State]
and when i run it I get a blank table
note(the state field on the form is what the [state]value in the table equles

thanks for help in advance
OK I figured it out but the purpose of this will be to loop though to send email(s) from the query.
when I loop though to populate my recipients is there a way to specify to only use distinct email address until .EOF
Ie: Im using send object method to send my email and and SendTo for my recipient field
so when I sent up my loop my SendTo would be SendTo = sendTo & .fields("Email") , but like i said a few lines up how would I state in this loop that SendTo = Sendto &.fields ("Email") but only distinct email address? I'm guesing:
SendTo = SendTo & .Distinct fields
help please , thanx in advance
Mar 8 '08 #2
Scott Price
1,384 Expert 1GB
Excuse me, but your question lacks quite a bit in clarity! Please post for us the relevant code that you are asking about, and state in clear language what it is you are trying to do.

Regards,
Scott
Mar 8 '08 #3
Excuse me, but your question lacks quite a bit in clarity! Please post for us the relevant code that you are asking about, and state in clear language what it is you are trying to do.

Regards,
Scott
ok I have code to open rst and select fields
to populate an email but how can I select distinct email addresses out of the rst (the rst is a query).
the problem I am having with my query rst now is when I run it I get an error "too fiew peramiters expected 3" (debuger highlights Set loRst = loDb.OpenRecordset("QryE-CallReport") )
but the same method works fine if the query is only comprised of one table , in this case it is two tables,
here is my query in Sql:
Expand|Select|Wrap|Line Numbers
  1. SELECT [VMSU-CLT].Date, [VMSU-CLT].Time, [VMSU-CLT].State, [VMSU-CLT].VISTALastName, [VMSU-CLT].VISTAFirstName, [VMSU-CLT].VISTAMiddleName, [VMSU-CLT].NSPID, [VMSU-CLT].ReasonForCall, StateEmpLU.RepEmail
  2. FROM [VMSU-CLT], StateEmpLU
  3. WHERE ((([VMSU-CLT].Date)>=[forms]![E-Report query]![DateFrom] And ([VMSU-CLT].Date)<=[forms]![E-Report query]![DateTo]) AND (([VMSU-CLT].State)=[forms]![E-Report query]![State]) AND ((StateEmpLU.State)=[forms]![E-Report query]![State]));

here is my code to populate an email:

Expand|Select|Wrap|Line Numbers
  1. Dim stcontents As String
  2. Dim loDb As DAO.Database
  3. Dim loRst As DAO.Recordset
  4. Set loDb = CurrentDb
  5. Set loRst = loDb.OpenRecordset("QryE-CallReport")
  6. With loRst
  7. Do Until .EOF
  8. SendTo = SendTo & .Fields("VMSUTech") & ","
  9. 'stcontents = stcontents & .Fields("VMSUTech") & ","
  10. .MoveNext
  11. Loop
  12. End With
  13.  
  14. loRst.Close
  15. Set loRst = Nothing
  16. Set loDb = Nothing
  17.  
  18.  
  19. stSubject = Me.subject
  20. stBody = Me.msgBody & stcontents
  21. DoCmd.SendObject , , acFormatTXT, SendTo, , also, stSubject, stBody, 1
  22.  
  23.  
  24.  
  25. Endd:
  26.  
  27. Exit_Print_Preview_Click:
  28.     Exit Sub
  29.  
  30. Err_cmdReport_Click:
  31.  
  32.     MsgBox Err.Description
  33.     Resume Exit_Print_Preview_Click
  34.  
  35.  
  36. End Sub
Thanks for helping.
Mar 8 '08 #4
Scott Price
1,384 Expert 1GB
First of all, you need to join your two tables in your query expression. The query you have will not return much of anything meaningful... You need to tell the database which field each table has in common that will be used to relate the email address field in one table to the chosen employee/person in the other table.

Second you can use the DISTINCT or DISTINCTROW keyword in the query to return a distinct value.

You can look into the Access help file, go to the Table of Contents or Topics (depending on your version) and look under Microsoft Jet SQL Reference. In the Data Manipulation Section the article for SELECT Statement will give you a link to an article that explains the uses and syntax for the ALL/DISTINCT/DISTINCTROW keywords.

Regards,
Scott
Mar 8 '08 #5
ok I have code to open rst and select fields
to populate an email but how can I select distinct email addresses out of the rst (the rst is a query).
the problem I am having with my query rst now is when I run it I get an error "too fiew peramiters expected 3" (debuger highlights Set loRst = loDb.OpenRecordset("QryE-CallReport") )
but the same method works fine if the query is only comprised of one table , in this case it is two tables,
here is my query in Sql:
Expand|Select|Wrap|Line Numbers
  1. SELECT [VMSU-CLT].Date, [VMSU-CLT].Time, [VMSU-CLT].State, [VMSU-CLT].VISTALastName, [VMSU-CLT].VISTAFirstName, [VMSU-CLT].VISTAMiddleName, [VMSU-CLT].NSPID, [VMSU-CLT].ReasonForCall, StateEmpLU.RepEmail
  2. FROM [VMSU-CLT], StateEmpLU
  3. WHERE ((([VMSU-CLT].Date)>=[forms]![E-Report query]![DateFrom] And ([VMSU-CLT].Date)<=[forms]![E-Report query]![DateTo]) AND (([VMSU-CLT].State)=[forms]![E-Report query]![State]) AND ((StateEmpLU.State)=[forms]![E-Report query]![State]));

here is my code to populate an email:

Expand|Select|Wrap|Line Numbers
  1. Dim stcontents As String
  2. Dim loDb As DAO.Database
  3. Dim loRst As DAO.Recordset
  4. Set loDb = CurrentDb
  5. Set loRst = loDb.OpenRecordset("QryE-CallReport")
  6. With loRst
  7. Do Until .EOF
  8. SendTo = SendTo & .Fields("VMSUTech") & ","
  9. 'stcontents = stcontents & .Fields("VMSUTech") & ","
  10. .MoveNext
  11. Loop
  12. End With
  13.  
  14. loRst.Close
  15. Set loRst = Nothing
  16. Set loDb = Nothing
  17.  
  18.  
  19. stSubject = Me.subject
  20. stBody = Me.msgBody & stcontents
  21. DoCmd.SendObject , , acFormatTXT, SendTo, , also, stSubject, stBody, 1
  22.  
  23.  
  24.  
  25. Endd:
  26.  
  27. Exit_Print_Preview_Click:
  28.     Exit Sub
  29.  
  30. Err_cmdReport_Click:
  31.  
  32.     MsgBox Err.Description
  33.     Resume Exit_Print_Preview_Click
  34.  
  35.  
  36. End Sub
Thanks for helping.
I managed to solve by changing my code to reflect the tables instead of a query :
Expand|Select|Wrap|Line Numbers
  1. Dim qryDB As DAO.Database
  2. Dim loRst As DAO.Recordset
  3. Dim loRst1 As DAO.Recordset
  4. Set loRst = CurrentDb.OpenRecordset("SELECT * FROM [VMSU-CLT] WHERE" _
  5. & " [State]= '" & Me.[State] & "';")
  6. Set loRst1 = CurrentDb.OpenRecordset("SELECT * FROM [StateEmpLU] WHERE" _
  7. & " [State]= '" & Me.[State] & "';")
  8. With loRst
  9. With loRst1
  10. Do Until .EOF
  11. SendTo = SendTo & loRst1.Fields("RepEmail") & ""
  12. stBody = stBody & "Date: " & loRst.Fields("Date") & Chr$(9) & loRst.Fields("Time") & ","
  13. .MoveNext
  14. Loop
  15. End With: End With
  16.  
  17. loRst.Close: loRst1.Close
  18. Set loRst = Nothing: Set loRst1 = Nothing
  19. Set loDb = Nothing
  20. EditMessage = 1
  21. stSubject = "test"
  22.  
  23. DoCmd.SendObject , , acFormatTXT, SendTo, , also, stSubject, stBody, 1
note: there are a few doble arguments but I am takeing care of those as I compile stbody
thanks to those who replied
I need to add to my where clause a date from and date to on the [VMSU-CLT] Table
can someone help
Mar 8 '08 #6
I managed to solve by changing my code to reflect the tables instead of a query :

Dim qryDB As DAO.Database
Dim loRst As DAO.Recordset
Dim loRst1 As DAO.Recordset
Set loRst = CurrentDb.OpenRecordset("SELECT * FROM [VMSU-CLT] WHERE" _
& " [State]= '" & Me.[State] & "';")
Set loRst1 = CurrentDb.OpenRecordset("SELECT * FROM [StateEmpLU] WHERE" _
& " [State]= '" & Me.[State] & "';")
With loRst
With loRst1
Do Until .EOF
SendTo = SendTo & loRst1.Fields("RepEmail") & ""
stBody = stBody & "Date: " & loRst.Fields("Date") & Chr$(9) & loRst.Fields("Time") & ","
.MoveNext
Loop
End With: End With

loRst.Close: loRst1.Close
Set loRst = Nothing: Set loRst1 = Nothing
Set loDb = Nothing
EditMessage = 1
stSubject = "test"

DoCmd.SendObject , , acFormatTXT, SendTo, , also, stSubject, stBody, 1

note: there are a few doble arguments but I am takeing care of those as I compile stbody
thanks to those who replied
I need to add to my where clause a date from and date to on the [VMSU-CLT] Table
can someone help
this is supose to select only those records where the state = Me.state and the record date is between Me.Datefrom and Me.DateTo
but when I added the date argument to the where clause it seems to bypass my state = Me.state argument and only produces the records between those dates
Expand|Select|Wrap|Line Numbers
  1. Set loRst = CurrentDb.OpenRecordset("SELECT * FROM [VMSU-CLT] WHERE" _
  2. & " [State]= '" & Me.[State] & "' & [Date]>= '" & Me.[DateFrom] & "' & [Date]<= '" & Me.[DateTo] & "';")
what am I doing wrong here?
Mar 9 '08 #7
Stewart Ross
2,545 Expert Mod 2GB
Hi. In the date part of your WHERE clause you've mistakenly used ampersands in place of ANDs - easy to do and not so easy to spot it once it's written.
Expand|Select|Wrap|Line Numbers
  1. set loRst ... WHERE" & " [State]= '" & Me.[State] & "' & [Date]>= '" & Me.[DateFrom] & "' & [Date]<= '" & Me.[DateTo] & "';")
It is unlikely to be selecting records between the correct dates at present and certainly can't filter the State values. Replacing the ampersands:
Expand|Select|Wrap|Line Numbers
  1. Set loRst ... WHERE" & " [State]= '" & Me.[State] & "' AND [Date]>= '" & Me.[DateFrom] & "' AND [Date]<= '" & Me.[DateTo] & "';")
-Stewart
Mar 9 '08 #8
NeoPa
32,556 Expert Mod 16PB
this is supose to select only those records where the state = Me.state and the record date is between Me.Datefrom and Me.DateTo
but when I added the date argument to the where clause it seems to bypass my state = Me.state argument and only produces the records between those dates

Set loRst = CurrentDb.OpenRecordset("SELECT * FROM [VMSU-CLT] WHERE" _
& " [State]= '" & Me.[State] & "' & [Date]>= '" & Me.[DateFrom] & "' & [Date]<= '" & Me.[DateTo] & "';")
what am I doing wrong here?
Trevor,

Two of your posts IN THIS THREAD have already been edited for you to add the [ CODE ] tags that are required when posting code on this site (See How to Ask a Question). Please remember in future to put your code in the tags provide.

Admin.
Mar 9 '08 #9
Trevor,

Two of your posts IN THIS THREAD have already been edited for you to add the [ CODE ] tags that are required when posting code on this site (See How to Ask a Question). Please remember in future to put your code in the tags provide.

Admin.
I am now getting an error 3464 error in critrea and highlights my query:
Expand|Select|Wrap|Line Numbers
  1. Set loRst = CurrentDb.OpenRecordset("SELECT * FROM [VMSU-CLT] WHERE" & " [State]= '" & Me.[State] & "' AND [Date]>= '" & Me.[DateFrom] & "' AND [Date]<= '" & Me.[DateTo] & "';")
Mar 9 '08 #10
Stewart Ross
2,545 Expert Mod 2GB
I am now getting an error 3464 error in critrea and highlights my query:
Expand|Select|Wrap|Line Numbers
  1. Set loRst = CurrentDb.OpenRecordset("SELECT * FROM [VMSU-CLT] WHERE" & " [State]= '" & Me.[State] & "' AND [Date]>= '" & Me.[DateFrom] & "' AND [Date]<= '" & Me.[DateTo] & "';")
  2.  
Hi Trevor. I hadn't spotted earlier that in addition to your ampersand issue you were using quotes on either side of your dates, which treats the dates as if they were string literals. Assuming Date and DateTo are indeed of type date, these should be enclosed by hashes, not single quotes:
Expand|Select|Wrap|Line Numbers
  1. Set loRst = CurrentDb.OpenRecordset("SELECT * FROM [VMSU-CLT] WHERE [State]= '" & Me.[State] & "' AND [Date]>= #" & Me.[DateFrom] & "# AND [Date]<= #" & Me.[DateTo] & "#;")
  2.  
As an aside, although in a table definition it is legal to have a field called Date of type Date/Time, it is not good naming practice. Use of this field may be confused with the in-built Date function.

-Stewart

ps I am assuming that your State value is also a string, as it too is in single quotes. if it isn't remove the single quotes from either side.
Mar 9 '08 #11

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

Similar topics

5
by: Don Seckler | last post by:
I have an update query that runs when a report closes. I have several reports that will need to run the update query with diferent criteria. I'd like to simply make the criteria change in the...
2
by: RBohannon | last post by:
I have a report with most fields populated by a query. However, some of the fields are variable in such a way that their values cannot be queried from a table. At present the values for these...
1
by: JM | last post by:
Hello, Using Access 2000 queries, you can reference(pass) form values directly using syntax like Forms!frmPaint!txtColor. I want to do a pass through query to SQL Server 2000, but I don't know...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
2
by: ILCSP | last post by:
Hello again, I'm still in the process of changing ms access queries to Pass through queries. We're using a SQL Server 2000 database with an Access 2000 DB as our front end. I trying to convert...
4
by: Fendi Baba | last post by:
I am creating a simple project information database. In the project information form 1 have two subforms. one contains organization involved - many organzation can be involved - and another list of...
6
by: Bez | last post by:
I have created a querie from a Form with differents search criteria on the form when i search for a comopany begining with "a" for example it will bring up all the companies begining with "a" but...
10
by: sesling | last post by:
I have created a query that will pull information from our database for the operators. This query will pull in on average 50,000 records. The operators need to refine the search results. I have...
2
by: Bob Alston | last post by:
If you have an access form with record source being a straightforward query and where clause in the form definition, will the query be sent to the back end jet/Access database and executed there,...
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
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
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...
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,...

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.