Group meetings MS ACCESS - ms-access-2007

I have a database that monitors staff leave and training, every 8 weeks a group will gather and then do training, what i am after is a way to rather than individually assign each member a training event id rather open the event and select the participants, from here each staff member will have this specific training logged against them
So far i have each staff recognised by ID and each training by GID but am having trouble entering this training event in against all IDs?

This BULK INSERT could be probably done by using an Unbound Form. The minimal controls would be one Listbox, ComboBox, a TextBox and a Button.
ListBox (staffList), which should be allowed to select multiple items; will obtain its RowSource from the Staff table, something like
SELECT
staffID,
staffName
FROM
staffTable;
The properties would be Bound Column : 1, Column Count : 2, Column Widths : 0cm;2.542cm
The ComboBox (eventCombo), will obtain its RowSource from the Event table, something like
SELECT
eventID,
eventName
FROM
eventTable;
The properties would be Bound Column : 1, Column Count : 2, Column Widths : 0cm;2.542cm
Then the TextBox (dateTxt) would just have a Date control (for the date of the event).
The code behind the Button (addEventBtn) click would simply be,
Private Sub addEventBtn_Click()
Dim varItem As Variant
If Me.staffList.ListIndex = -1 Then
MsgBox "No Staff selected. You have to select at least one staff before you can proceed !", vbCritical
Me.dateTxt.SetFocus
Exit Sub
End If
If Me.eventCombo.ListIndex = -1 Then
MsgBox "No Event selected. You have to select at least one staff before you can proceed !", vbCritical
Me.dateTxt.SetFocus
Exit Sub
End If
If IsNull(Me.dateTxt) Then
MsgBox "No Date selected. You have to select Date before you can proceed !", vbCritical
Me.dateTxt.SetFocus
Exit Sub
End If
For Each varItem In Me.staffList.ItemsSelected
CurrentDB.Execute "INSERT INTO tbl_EventList (eventID_FK, staffID_FK, eventDate) VALUES (" & _
Me.eventCombo & ", " & Me.staffList.ItemData(varItem) & ", " & Format(Me.dateTxt, "\#mm\/dd\/yyyy\#") & ")"
Next
End Sub
This should work out. Please change it according to your design ! If you have any questions please add them to comments.

Related

Ensure Unique Records in Form (MS Access)

Using a Form in MS Access, I need to ensure only unique records are entered into the table.
It's unfortunately in a situation where I can't enforce unique records via the table's primary keys.
I have the following code in the BeforeUpdate for the Form, but it is not working. Any help would be greatly appreciated!
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "[Role_Details]", "[Role] = " & Me.[ComboRole] & " AND [Session] = " & Me.[ComboSession]) > 0 Then
MsgBox "Duplicate!"
Cancel = True
Me.[ComboSession].SetFocus
Exit Sub
End If
End Sub
Note: The table name is "Role_Details". Field names are "Role" and "Session". With "ComboRole" and "ComboSession" being the Form Field Labels.
Any thoughts on where I've gone wrong here?
Updates##
When I open the DataSheet Form, it presents a popup box saying "Enter Parameter Value" and "frm_Role_Details.Session". I'm not sure why this is, but I can enter past it and open the Form.
Then, them i'm entering a record an error pops up saying "Run-time error '2465': Can't find the field '|1' referred to in your expression. Both Fields are Text Strings. I'm at a loss!
When concatenating in VBA, text fields require apostrophe delimiters for inputs.
If DCount("*", "[Role_Details]", "[Role] = '" & Me.[ComboRole] & "' AND [Session] = '" & Me.[ComboSession] & "'")> 0 Then
Date/Time fields use # delimiter.
Number fields do not use any delimiter.

Filter records based on a combo box selection

OS - Win 10
Office 365
Hello,
I am attempting to create a form with a combo box to filter results.
I have one table that I want to filter. The filter is one of the columns in the table (using unique values from that column).
The following code returns a "Data type mismatch in criteria expression" error;
Sub SetFilter()
Me.cboAcc.RowSource = "select * from frmQryLedger where ACCOUNT_ID = '" & Me.cboAcc & "'"
'For trouble shooting
MsgBox Me.cboAcc.RowSource
End Sub
Private Sub cboAcc_AfterUpdate()
'Call subroutine to set filter based on selected ACCOUNT_ID
SetFilter
End Sub
Thank You
Ben

Retrieving most recent value in Microsoft Access form based on another value

I have a form built for the team to log calls made to customers. They may have multiple calls with the same customer who all have a unique ID assigned. I've built a form so that the team member can select a customer ID in the combo box and then using VBA, unbound text boxes will display the customer's name, phone number, and address (which is stored on a customer demographics table). All of this part so far has been working just fine.
My problem is that there is a text box on my form where team members can insert notes about the call. I've been asked by the team lead to make it so that when the customerID is selected, that notes box automatically populates with the last call's notes, and that team members can enter add on more notes. So for example in the last call on 4/1, the notes were "4/1 - Spoke to customer, order is on the way", and now it's 4/8, they're calling customer and want to see the last notes, the box should show that note from 4/1. Is there a way to do this? I've tried using the combo box option tying this to the customer ID combo box but can't quite get it to work. Thank you!
SELECT Notes,
CustID FROM (SELECT Call1.CustID,
Count(*) AS Rank,
Call1.DateCalled, Call1.Notes FROM Call AS Call1
INNER JOIN Call AS Call2 ON Call1.CustID = Call2.CustID
WHERE ((Call2.DateCalled>=Call1.DateCalled))
GROUP BY Call1.CustID, Call1.DateCalled ORDER BY 1, 2) WHERE Rank=1) AS Call ON CustTable.CustID=Call.[CustID]
Below is some VBA code that gets the last set of notes (by using TOP/ORDER BY DateCalled DESC) for the current customer as selected in a combo box where DateCalled doesn't equal the current call date (shown in txtDateCalled):
Private Sub Combo0_AfterUpdate()
On Error GoTo E_Handle
Dim db As DAO.Database
Dim rsData As DAO.Recordset
Dim strSQL As String
Set db = DBEngine(0)(0)
strSQL = "SELECT TOP 1 Notes " _
& " FROM Call " _
& " WHERE CustID=" & Me!Combo0 _
& " AND DateCalled<>" & Format(txtDateCalled, "\#mm\/dd\/yyyy\#") _
& " ORDER BY DateCalled DESC;"
Set rsData = db.OpenRecordset(strSQL)
If Not (rsData.BOF And rsData.EOF) Then
Me!txtLastNotes = rsData!Notes
Else
Me!txtLastNotes = ""
End If
sExit:
On Error Resume Next
rsData.Close
Set rsData = Nothing
Set db = Nothing
Exit Sub
E_Handle:
MsgBox Err.Description & vbCrLf & vbCrLf & "frmCall!Combo0_AfterUpdate", vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
In order to populate the other text boxes, which are based on the Customer table, you may want to look at adding the columns to the combo box, with their ColumnWidth set to 0 (so the user can't see them), and then set these text boxes to use the hidden columns.
Regards,

find duplicate with if statement then delete duplicate

I have a table (BERTHAGE) that tracks the location of vessels when they are in the port.
When a vessel moves from one location to another location I process the move through a form which is tied into a combo box.
I use one combo box (tied into a query) to give me the current list of vessels in port.
From there I select the vessel that is moving.
Once the vessel is selected I use another combo box to select the new location.
From there I click the Save button and the record is saved in the appropriate table with the vessel now tied into the new location.
The issue I am having is that the prior location record still exists in the same table (BERTHAGE).
So now I have two records for one vessel in the same week, this becomes an issue when it comes to invoicing.
What I’m trying to do is eliminate one of the entries and of course it must be the older entry/former location of the vessel.
Because each entry is assigned an auto-number (primary key) the newest entry, the movement of the vessel from one location to another, will always have the higher auto number.
I have been trying to come up with a way to find the duplicate in the table (BERTHAGE), based on the vessel name and then delete the older entry with the duplicate vessel name.
It seems the only way to go about this is a series of queries (find duplicate, append) and this ends in over writing the entire table each time. I’m trying to avoid this and stick with the goal of only deleting any duplicates that are occurring that week when a vessel moves from one spot to another.
Though my scripting is average, I can’t help but to think that the best way to achieve this goal will be through something akin to an IF statement tied into the save button. I was hoping Access would have something similar to Excel's .RemoveDuplicates, but to date I have found not found it.
Looking for any pointers people may have.
Private Sub Form_Load()
DoCmd.RunCommand acCmdRecordsGoToLast
End Sub
Private Sub cmd_Clear_Click()
Me.Boat_New_Loc = ""
Me.CrNum.value = ""
Me.CrDockValue.value = ""
Me.CrFloatValue.value = ""
Me.CrOriValue.value = ""
Me.SelectNewLoc.value = ""
Me.cmd_berthed.value = ""
Me.NewFloatValue.value = ""
Me.NewDockValue.value = ""
Me.NewOrieValue.value = ""
End Sub
Private Sub Boat_New_Loc_Change()
Me.CrNum.value = Me.Boat_New_Loc.Column(4)
Me.CrDockValue.value = Me.Boat_New_Loc.Column(5)
Me.CrFloatValue.value = Me.Boat_New_Loc.Column(6)
Me.CrOriValue.value = Me.Boat_New_Loc.Column(7)
End Sub
Private Sub SelectNewLoc_Change()
Me.NewFloatValue.value = Me.SelectNewLoc.Column(1)
Me.NewDockValue.value = Me.SelectNewLoc.Column(2)
Me.NewOrieValue.value = Me.SelectNewLoc.Column(3)
End Sub
Private Sub Save_Code_But_Click()
DoCmd.RunSQL "UPDATE BERTHAGE SET BERTHAGE.LOCATION=False WHERE LOCATION=" & Me!CrNum _
& " AND LOCATION <>" _
& Me!SelectNewLoc & _
" AND BERTHAGE.LOCATION=True;"
DoCmd.Save acForm, "Change_Boat_Location3"
cmd_Clear_Click
End Sub
Rather than deleting the record, I would advise setting a flag in the table to indicate that it is not active. This means that you can recreate historical data if needed.
In my examples, I am going to assume that the table Berthage has a primay key field called ID that is an Autonumber, a field VesselID that is a numeric foreign key from a Vessel table that gives information about the vessels, and also has BerthageActive, which is a Yes/No field.
If you are able to do the update before saving the new information in the Berthage table, then you can use:
CurrentDb.Execute "UPDATE Berthage SET BerthageActive=False WHERE VesselID=" & Me!VesselID & " AND BerthageActive=True;"
If the new data already exists in the Berthage table, then you can use:
CurrentDb.Execute "UPDATE Berthage SET BerthageActive=False WHERE VesselID=" & Me!VesselID & " AND ID<>" & Me!ID & " AND BerthageActive=True;"
Regards,

Combo Box depends on another combo box

I have a form with two combo boxes, one Wards the other room number. Wards are medical units, while the rooms are room numbers (like GMU-01).
I'm trying to limit the room names based on the wards value, ie list all the bed numbers for a particular unit.
SELECT DISTINCT [TblWards].[Wards] FROM TblWards ORDER BY [TblWards].[Wards];
The row source from the Wards combo box (First box)
Private Sub Wards_AfterUpdate()
Dim txt As String
txt = "SELECT TblWards.Room FROM TblWards WHERE (TblWards.Wards)= '" &
Me.Wards.Column(0) & "' ORDER BY TblWards.Room;"
Me.RoomN.RowSource = txt
End Sub
SELECT [TblWards].[Room] FROM TblWards WHERE ((([TblWards].[Wards])=AMU));
The row source from the second combo box RoomN
I get an error when I attempt to choose a value from the Wards combo box. If I line out the afterupdate code, I can choose a value. The error is unexpected error, access needs to shut down.
Then, I get an error if I attempt to select a value from the second combobox. asking for the AMU parameter.
I inherited this code and trying to determine how to go about it, rewrite or try to salvage it.
from what I understand from your message, you can try this:
Private Sub cboWard_AfterUpdate()
Dim strSQL As String
strSQL = "SELECT * FROM tblRooms WHERE rWardID = " & Me.cboWard
Me.cboRoom.RowSource = strSQL
End Sub
Try Following-
Clear ControlSource and RowSorce Property of comboBox 'RoomN' Manually.
Try following code in AfterEvent of 'Wards' comboBox
Private Sub Wards_AfterUpdate()
Dim txt As String
txt = "SELECT Room FROM TblWards WHERE [Wards] = '" & Me.Wards.Value & "' ORDER BY Room;"
Me.RoomN.RowSource = txt
End Sub