Access VBA - getting value of current record - ms-access

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.

Related

Query: typing multiple criteria in a textbox form

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.

Query multiple records between "Weeks" where no record in child table

I am trying to determine the best method for how to handle this query using Access 2013. I have a clients table that contains the following:
clientID fName lName admissionDate dischargeDate
1 John Doe 05/06/2014 06/27/2014
2 Jane Doe 04/24/2014 05/15/2014
3 Steven Smith 05/15/2014 NULL/Empty
4 Chris Davis 06/12/2014 NULL/Empty
Then there is a WeeklyProgressNotes table that is there for the person that is responsible for auditing the clients charts. It does not contain the actual weeklyprogressnotes, it only contains a Yes/No field and a date field for the date the weeklyprogressnote was completed. Like below:
noteID completed dateCompleted clientID
1 yes 05/08/2014 1
2 yes 05/14/2014 1
3 yes 04/25/2014 2
I am creating a form that the auditor can open to determine what weeks she needs to check for each client to see if they have their weeklyprogressnotes completed that week. The weeks run Mon - Sun and there will be no record in the WeeklyProgressNotes table if she has not yet checked and confirmed for that week. So the form would basically look like this:
fName lName week completed date clientID(hidden)
John Doe 5/19/14-5/25/14 Checkbox Null 1
John Doe 5/26/14-6/1/14 Checkbox Null 1
John Doe 6/2/14-6/8/14 Checkbox Null 1
John Doe 6/9/14-6/15/14 Checkbox Null 1
John Doe 6/16/14-6/22/14 Checkbox Null 1
John Doe 6/23/14-6/29/14 Checkbox Null 1
Jane Doe 4/28/14-5/4/14 Checkbox Null 2
and so on.......
I have thought about creating an SQL statement to select all of the clients and then creating a function that determines their admission date within the specific week and their discharge date withing the specific week and then create a loop with another SQL statement with a BETWEEN clause for all the weeks and determine if there is an entry in the WeeklyProgressNotes table or not. If not then I would display out the above info. I'm not sure if there is an easier, less search intensive way of doing it. Maybe an SQL query that can cut done on some of the looping.
The way I would address this problem, is to create a new table. Since you want to split up date time between addmission and discharge date into multiple rows, I think it would be best to split the client in multiple records in a table.
The following code creates a recordset based on your basic clients table. Afterwards it creates your temporary table (Here populated by only 2 fields due to a lack of time). When you loop through the recordset of your original table, you hold on each row and split the time between the addmission and dischargedate in blocks of one week.
Afterwards, once you have populated the table, it is easy to create a simple query based on this table and the table with the weeklyprogressnotes.
I hope my explanation was sufficient and please note that I have not tested the code yet. It will most likely require some tweaking on your behalf. Perhaps I can look at it later on if I've got some more time on my hands.
Sub showrecords()
Dim gvweek As String
Dim rs As Recordset
Dim rstemp As Recordset
Dim tdfNew As TableDef
gvweek = ""
Set tdfNew = CurrentDb.CreateTableDef("Tbl_Temporary")
With tdfNew
.Fields.Append .CreateField("fName", dbText)
.Fields.Append .CreateField("week", dbText)
End With
Set rs = CurrentDb.OpenRecordset("Clients")
With rs
Do Until .EOF
.MoveFirst
Do Until DateAdd("dd", 7, ![admissionDate]) > ![dischargeDate]
gvweek = ![admissionDate] & " - " & DateAdd("dd", 7, ![admissionDate])
Set rstemp = CurrentDb.OpenRecordset("Tbl_Temporary")
With rstemp
.AddNew
![fName] = rs![fName]
![week] = gvweek
.Update
End With
rstemp.Close
Set rstemp = Nothing
Loop
gvweek = ""
.MoveNext
Loop
End With
rs.Close
Set rs = Nothing
DoCmd.DeleteObject acTable, "Tbl_Temporary"
End Sub

Sequence Number in ms access

I want to create sequence number in my order form that after save button it generate a Order No in Order No field of table, as I m not much knowledge in VBA but got from internet some codes which i try to implement but its not working
The code is given below please see reply if there is any edit or where i m mistaked
Table:
ID | date | party Name | Order No| Item | qty | Rate | Amount |
Private Sub save_Click()
If Me.orderno = Null Then
Me.orderno = Nz(DMax([Order No], Order), 0) + 1
End If
End Sub
If the name of the table is 'Order', the following should work:
If IsNull(Me.orderno) Then
Me.orderno = Nz(DMax("[Order No]", "Order"), 0) + 1
End If
A few other comments:
Date is a reserved word and should not be used as a field name, so best to change it to avoid problems. http://office.microsoft.com/en-us/access-help/access-2007-reserved-words-and-symbols-HA010030643.aspx
It is also poor practice to use spaces in field names.
The problems here were quite obvious, however, for future reference, you should state what error you are receiving and which line it occurs on. 'Not working' does not provide any clues.
Add the line
DoCmd.RunCommand acCmdSaveRecord
at the end, to insure that the record is saved.
Make sure that the code is actually running and that orderno is bound to the field orderno.
If it still doesn't appear to work, step through he code to see what is happening.
As for the comment about autonumber, and autonumber is fine if you don't care about gaps in the numbering sequence, which will eventually occur using an autonumber.

Microsoft Access selecting records from another table matching current record

It seems I've hit a brick wall in MS Access 2010.
It's kind of hard to explain what I'm trying to achieve, so I'll start with a basic example. Let's say we have two tables: A and B.
A:
ID Price Item
1 5 ABB
2 4 ATV
3 2 CCC
B:
ID Price limit Chosen item
1 3
2 4
3 5
4 6
What I'm trying to achieve is create a Relation from table A to B. Each record in table B has to have associated table A record. It should be based on table A field 'Price' and table B field 'Price limit' in a way that the price of selected record from Table A is lower than the price limit imposed in table B record.
That is, the possible table A records for the first table B record is only CCC, for second - ATV and CCC, while for third and fourth all records are valid.
As far as my limited access knowledge goes, I've figured that I should write a query in "Chosen item" field row source property. I've tried writing it myself, however, without success. Here's what I've come up with:
SELECT [Table A].[ID], [Table A].[Item]
FROM [Table A]
WHERE [Table A].[Val] > [Val];
But it does not work. Could somebody please point me to the right direction?
I think that you want something like this where the dropdown box only contains relevant items:
You can set this up by setting the row source of the combo to say,
select item from ta where price<=forms!tb!pricelimit
And adding a little code
Private Sub Form_Current()
Me.Chosenitem.Requery
End Sub
Note that this method comes with a warning. Usong dropdowns like this on a continuous form can seriously mess up the display of your data on any rows other than the current row. In this case, the display is fine, because the bound column and the data to be displayed are the same, however, if the selection was:
Row Source: select id,item from ta where price<=forms!tb!pricelimit
Bound Column: 1
Column Widths : 0cm;2cm
Data would appear to disappear from records when the selection for the current record produced a list that did not contain IDs for other rows. That is to say, if the selection for the current rows returned IDs 1 and 2 and the next row already had ID 3 chosen, the combo for the next row would appear to empty, and so on down the page.

Update Query Access

I am trying to update a field inside one table, "Todays_Deliveries", from another table called "Current_Delivery". The field is a number field called "Remaining" which describes how many units there are of a particular item left on the daily deliveries.
The "Todays_Deliveries" table is generated using an APPEND query from another master table with every delivery stored in it. Everytime the user opens a delivery on a form anything in the "Current_Delivery" table is removed using a DELETE query and then generated based on the delivery selected using an APPEND query from the "Todays_Deliveries" table.
Both tables have identical fields and identical values, given one is generated from the data of the other.
I have tried to create an UPDATE query to update the "Todays_Deliveries" table when a user edits the "Current_Delivery" table but it doesn't work. I recieve no error messages the field just doesn't update. The steps I took were as follows:
Add both tables.
Change to UPDATE query.
Link tables using the Remaining field.
Set the Field: Remaining and
Set the Table: Current_Delivery.
Set Update To: [Todays_Deliveries].[Remaining].
Any advice/help would be greatly appreciated.
EDIT:
BEFORE:
Todays_Deliveries
ID Date Time Ref Studio Description Total Remaining
3187 23-Oct-12 10:00 3663 ROCK PINK 1900 1900
Current_Delivery
ID Date Time Ref Studio Description Total Remaining
3187 23-Oct-12 10:00 3663 ROCK PINK 1900 1000
AFTER:
Todays_Deliveries
ID Date Time Ref Studio Description Total Remaining
3187 23-Oct-12 10:00 3663 ROCK PINK 1900 1000
UPDATE:
I've got the query working using the below function
UPDATE Todays_Deliveries SET Remaining = DLookup("Remaining","Current_Delivery","[MP-Ref] = Form![MP-Ref] And [Cat No] ='" & [Cat No] & "'")
WHERE "[MP-Ref] = Form![MP-Ref] And [Cat No] ='" & [Cat No] & "'";
Where MP-Ref is the delivery reference that list a number of items, and Cat No is the individual item reference.
The only problem is the other items in the _Daily_Deliveries_ table, the ones not in the _Current_Delivery_ table, have there remaining field set to 0 when I run it. Is there anyway to stop this?