Query: typing multiple criteria in a textbox form - ms-access

My question is about how to query multiple values in a field in a form in Access 2016. In the form, I have 3 textboxes: Date1, Date2 and studentID (txtstd_id)
In txtbox1 I select date 1
In txtbox2 I select date 2
In txtbox3 I type one value (e.g, student_ID)
Below I show SQL for dates and SQL for std_id. I used the query builder.
SQL1 = Between [Forms]![frm_search]![txtdatte1] AND [Forms]![frm_search]![txtdatte2]
SQL2 = [Forms]![frm_search]![txtstd_id]
SQL1 and SQL work well.
Now, what I need is to enter in txtstd_id more than one value -using OR clause- hoping that Access will returns all txtstd_id values between the date range selected.
Any idea is welcome.
I hope this example helps me to be clear:
I have a form with three text boxes: one for Day1, one of Day2 and one for Room.
The for also has a Search Button to run the Query
My Query sentence is:
SELECT tblsch1.datte, tblsch1.room, tblsch1.std_ID
FROM tblsch1
WHERE (((tblsch1.datte) Between [Formularios]![frm_Search]![txtday1] And [Formularios]![frm_Search]![txtday2]) AND ((tblsch1.room)=[Formularios]![frm_Search]![txtroom]))
ORDER BY tblsch1.datte, tblsch1.room;ter code here
For example in Day1 user selects 16/04/2018 and 21/04/2018 in Day2 and enter 6 in Room. Then. when a user clicks Search Button Access displays the query with desired data, otherwise displays "This period has no records".
With same date range user delete 6 and enters 9 and click again button search, then Access displays the query.
With same date range user delete 9 and enters 10 and click again button search, then Access displays the query.
What I am looking for is to allow a user in Room textbox to enter 6 OR 9 OR 10 at a time.

Related

MS Access Crosstab Query w/ Date Parameter Not Working Properly

I have a MS Access Table with the following information
DA Attendance
Attendance ID (Key)
Date
DA
Attendance Record (Dropdown with 6 options)
Note
I am trying to create a cross tab query that will display the following:
Query Result Example
I am able to get the crosstab query without any date parameters to work as intended. The picture above is how it looks. However, when I add the parameter I get the following error: "The expression is typed incorrectly, or is too complex to be evaluated..." . I have a form in which the user inputs a specific day for which to create the query.
Query Design 1
Query Design 2
Raw Data Example
Attendance ID
DA
Date
Attendance Record
Note
1
65
2021-09-16
Present
2
37
2021-09-16
No Call No Show
No text response
3
25
2021-09-16
Tardy
1155 AM arrival
4
58
2021-09-16
Present
PARAMETERS [Forms]![DA Attendance Form]![DA_Attendance_Date] DateTime;
TRANSFORM Count([DA Attendance].[Attendance ID]) AS [CountOfAttendance ID]
SELECT [DA Attendance].DA
FROM [DA Attendance]
WHERE ((([DA Attendance].Date)=[Forms]![DA Attendance Form]![DA_Attendance_Date]))
GROUP BY [DA Attendance].DA
PIVOT [DA Attendance].[Attendance Record];
Figured out the issue. MS Access is acting as the front end for a SQL Server database. The field "Date" was declared as type Date() in SQL Server which for whatever reason pulled as "Short Text" in Access. Edited the field type to DateTime() in SQL Server and it solved the issues when running the query.

how to calculate sum of row in crystal report using sql query, and do not display if the sum equals to 0.00

I have the following crystal report, I want to calculate the sum of each row of specific columns:
Opening Quantity
Purchase Quantity
Issue Quantity
if sum of the above 3 columns is equal to 0.00, then do not print that record.
Please look out at the screenshot of generated report:
I am to guess here that the fields are placed in the DETAIL section , if then you can use the suppress formula(Section Expert-->Detail Section-->Suppress formula)
and try something like this
{Opening Quantity field} + {Purchase Quantity field} + {Issue Quantity field} = 0
I think this can give some idea to you
1) you have to create a formula to sum up the opening quantity, purchase quantity and Issue quantity by using Running Total Field.
Let say your field name for opening quantity inside the TableA is 'opening quantity'.
Thus, choose Table A, inside the Running Total Field and find the 'opening quantity'.
Then, choose 'SUM' as Type of Summary.
Do the same for another two fields.
At last, you will have 3 different running total field formula.
2) combine together these 3 formula inside one new formula.
Your final formula should look like this.
Let say you name it as Formula 4
if {#Formula1}+{#Formula2}+{#Formula3}<>0 then {#formula1}+{#formula2}+{#formula3}
then you drag this formula to any space in the report that you want the total to appear.
3) After drag it, right click on the formula and press 'Format Object'
Check the suppress box and write this inside the blue cross tab beside the suppress checkbox
{#Formula4}=0

Access VBA - getting value of current record

I'm a very new user of Access 2016 - I have a form populated by a query, and I want to create a hyperlink out of one of the text boxes. The link should include the combined values of the workday and taskID fields for the specific record the user clicks on.
My problem is that I can't figure out how to get the value of the current record. The control source for these columns are the values themselves, retrieved via the query populating the form's record source. The following code creates the link I want, but it returns the same workday and taskID values every time, regardless of what I click on, and I can't figure out how to make it respect the current record. Any help would be greatly appreciated!
Private Sub workday_Click()
Dim link As String
Dim workday as String
Dim taskID as string
workday = Format(Me!workday, "yyyy-mm-dd")
taskID = Me!taskID
link = "http://myurl.com/" & workday & "/" & taskID
Application.FollowHyperlink (link)
End Sub
EDIT - hope this helps explain a little better
The main table driving this has workID (PK), Workday, taskID, StatusID, DateLastUpdated, UpdatedByUserID. The query used for my form selects all from this table and joins in metadata tables for Task, Status and User. There are multiple records with the same workday value and the same taskID, but never the same combination of the two. The form has a few filters in the header, and the bottom section is a datasheet. In the datasheet I have a combo box used to update StatusID, all other fields are disabled and locked. My hyperlink click event is on the Workday field, and is working in that it creates the appropriate URL, it's just populated with the same taskID and workday values, eg even if I click on the row for "2016-07-12" "456", I still return "2016-07-11" & "123"
Here's a simplified version of what the data looks like. My goal is that when the user clicks on a workday, they are taken to a hyperlink made up of both the workday and TaskID of the row clicked on.
Workday TaskID
2016-07-11 123
2016-07-11 456
2016-07-11 789
2016-07-12 123
2016-07-12 456
2016-07-12 789
2016-07-13 123
2016-07-13 456
2016-07-13 789
I think I actually solved it - the problem was that since almost all fields were locked and disabled, the current record wasn't technically the row I was clicking on. I set Enabled = Yes for the Workday column, and now it's working as expected.

update combo box values in access 2007

Hi i have a combo box in a form (unbound form). The user has to enter some data, select a value from a combo box, push Save button, and then keep entering data until all the values from the combo are done. My combo has the RowSource Property set to a SELECT statement that retrieves all the data all the time. What i want: when the user selects a value from the combo and push the Save button the selected value gets removed from the combo. Example:
The combo has two values: -25 to 35 years
-36 to 45 years
The user selects a value :-36 to 45 years, enter other data and push Save button
As a result the combo should only have one option: -25 to 35 years
(after that it keeps on the same form, to enter data until no available options on combo)
Form: create a form with text box where you save select value with comma sparated string exmaple: "1","2","3" when you press the save button
Use the following SQL for the Dropdown, which will eliminate the selected value from the drop down
SQL query
SELECT Table1.Value
FROM Table1
WHERE (((Table1.Value) Not In ([Forms]![Form1]![Text0])));
Table:
table1
1
2
3
4
5
6
Result in drop down for above sql senerio
Result
4
5
6

Sql query to keep "counted" the rows that have been deleted

I have a classified site... I'm trying to make a sql query that COUNTS the number of ads the user has posted in last 7 days, but I have a problem...
I'm trying to show in user profile something like this for example: [Username] has posted 30 ads in last 7 days
Here is my sql query ->
SELECT COUNT(*)
FROM table_name
WHERE user_id = '[user_id]' AND created_date > NOW() - INTERVAL 7 DAY
So in my case "table_name" contains ALL the ads from all the users and by "user_id = '[user_id]'" I show the user A his number of ads, and to USER B his number of ads etc...
So this query works, it counts the number of ads correctly, BUT, if for example user enters on site and DELETE's 1,2 or whatever number of his ads, this number will be "minused" from the "[Username] has posted 30 ads in last 7 days"
So let's say for example user posted 20 ads in the last 5 days - The correct result is [Username] has posted 20 ads in last 7 days
Now user enters on site and delete's 4 ads - Now the result is [Username] has posted 16 ads in last 7 days
Can somebody help me please, what can I add to the query so the count still shows the correct number of ads (in my case 20 ads), even if the ads where deleted..
Thank you
Cheers
Instead of deleting a row using a DELETE ... WHERE ... statement, add a deleted column and use an UPDATE statement:
UPDATE ... SET deleted = 1 WHERE ...
Then your counting function will work without modification.
Of course you will now have to fix all the rest of your code to not show deleted adverts. You can do this by adding WHERE NOT deleted to all your other queries. You could also create a view that only shows ads that are not deleted and update your code to query this view instead of the original table.
Rather than deleting the ads from the system, add a "deleted" flag, or move them to a deleted table. This way you never lose the record of them.
There's nothing you can add to a query to find data which has been deleted. You need not to delete the data, but add a marker to the record the user wants to delete to indicate that it's been removed from display.
As well as allowing the record to be counted, it has the additional advantage that the user can be permitted to reinstate that advert, if he wants to.