Hi everybody,
I have an Employee table with the following: -
Table - Employee
-
--------------------------
-
ID: AutoNum, PK
-
FName: Text
-
LName: Text
-
Status: Yes/No
-
Status indicates whether the employee is active/inactive (employed/not employed) with the company.
I have a query setup that is based on the Employee table will show just the active employees.
I have a subform on a form that has a field for the active EmployeeIDs and uses the qryEmployeesAct ive as the rowsource. I have setup code, along with a dialog form, that will handle the standard error and then take the user to the dialog form so the user can enter in an employee that isn't in the list.
When initially setting this up, I failed to account for the fact that an employee might get rehired...that happens a lot where I work. Here's my code with the update: -
Private Sub EmployeeIDFK_NotInList(NewData As String, Response As Integer)
-
-
Dim strEmployeeID As String, strWhere As String
-
Dim addToListMessage As String, notInListMessage As String, notInListTitle As String
-
Dim notInListUpdate As String, notInListUpdateTitle As String
-
Dim previousEmployee As Boolean
-
Dim varEmployeeStatus As Integer, varEmployeeID As String
-
Dim strUpdate As String
-
-
addToListMessage = "The employee ID you entered is undefined." + Chr(13) + Chr(13) + "Do you want to add the employee?"
-
notInListMessage = "The employee you selected is not in the list. Please try again."
-
notInListTitle = "Employee: Not in List"
-
notInListUpdate = "The employee was successfully added."
-
notInListUpdateTitle = "List Updated"
-
-
strEmployeeID = NewData
-
-
strWhere = "[EmployeeID] = " & strEmployeeID
-
varEmployeeStatus = -1
-
-
'THIS IS THE PART I ADDED TO CHECK FOR AN EXISTING EMPLOYEE
-
'------------------------------------------------------------------------------------------------------------
-
If IsNull(DLookup("EmployeeID", "qryEmployees", strWhere)) Then
-
GoTo EmployeeNotInList
-
Else
-
If vbYes = MsgBox("The employee ID you entered is undefined, but is a previous employee." + Chr(13) + Chr(13) + "Do you want to reactivate the employee?", vbYesNo + vbQuestion, "Previous Employee") Then
-
Response = acDataErrContinue
-
strUpdate = "UPDATE qryEmployees " & _
-
"SET EmployeeStatus =" & varEmployeeStatus & " " & _
-
"WHERE [EmployeeID]= " & strEmployeeID & ";"
-
DoCmd.RunSQL strUpdate
-
'[Forms]![frmDeficiency].deficiencyTabControl.Pages(1).SetFocus
-
'[Forms]![frmDeficiency].Requery
-
'Me.EmployeeIDFK.Requery
-
'Me.EmployeeIDFK.SetFocus
-
-
GoTo EmployeeExit
-
Else
-
MsgBox notInListMessage, vbInformation, notInListTitle
-
Me.EmployeeIDFK.Value = Null
-
Response = acDataErrContinue
-
Exit Sub
-
End If
-
End If
-
-
'THE PART BELOW WORKS FINE WHEN CHECKING FOR EMPLOYEES NOT IN THE LIST, BUT NOT FOR AN EMPLOYEE THAT MAY BE RETURNING TO WORK AND NEEDS TO BE RE-ADDED TO THE ACTIVE QUERY
-
EmployeeNotInList:
-
If vbYes = MsgBox(addToListMessage, vbQuestion + vbYesNo, notInListTitle) Then
-
Forms!frmDeficiency.Visible = False
-
DoCmd.OpenForm "frmEmployeeAddition", DataMode:=acFormAdd, _
-
WindowMode:=acDialog, openArgs:=strEmployeeID
-
If IsNull(DLookup("EmployeeID", "qryEmployees", strWhere)) Then
-
MsgBox notInListMessage, vbInformation, notInListTitle
-
Me.EmployeeIDFK.Value = Null
-
Response = acDataErrContinue
-
Else
-
MsgBox notInListUpdate, vbInformation + vbOKOnly, notInListUpdateTitle
-
Response = acDataErrAdded
-
End If
-
Else
-
MsgBox notInListMessage, vbInformation, notInListTitle
-
Me.EmployeeIDFK.Value = Null
-
Response = acDataErrContinue
-
End If
-
-
EmployeeExit:
-
Exit Sub
-
-
End Sub
-
If I put an employee ID in the employee field that I know has already been entered in the employee table, it just keeps popping up the same previous employee messagebox. It won't return me to the form and it won't requery the combo box.
The SQL does update the query and shows the employee as active again, but it doesn't do me any good if the user can't choose the employee because the code still thinks it isn't in the list.
Do I need to explicitly reset the rowsource for the employee ID field on the subform each time or is there something I'm missing?
1 1870
Nevermind....I tried what I suggested and explicitly reset the rowsource and it worked. Because my rowsource was different from the query I was searching/updating, the message box kept popping up.
That's what I get for trying to create combo boxes with rowsources based on logical queries... :)-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andy Proctor |
last post by:
I hope there is an answer out there....
I have a simple database structured like this (non relevant tables and
fields omitted)
Members table
memberID
memberFname
memberLname
memberNokID
|
by: Heather |
last post by:
I want to make a message box appear on the NotInList event for several
combo boxes. The message box will alert the user that if they need to
add a value they must go through the database administrator. I have
some code that isn't working but I assume it's close. I just don't
know what to do next. Thanks!!
-------------
Private Sub cboSiteClass_NotInList(NewData As String, Response As
Integer)
Dim Msg As String
|
by: Greg Acuna |
last post by:
Is there a way to have new data entered into a combo box update the
row source table it is connected to?
|
by: whilstiwait |
last post by:
I have a form containing a number of unbound combo boxes in three
columns. Each column has boxes named "aaaa0", "aaaa1", etc. Using
syntax like:
With Forms(Me.Form.Name).Controls("txtTechnology" & i)
.AfterUpdate = "=txtTechnology_Change(" & i & ")"
.OnEnter = "=txtTechnology_OnEnter(" & i & ")"
End With
I can set events to a common routine for all the boxes, and in the
|
by: Bryan |
last post by:
I have a listbox that the user is able to add items to through and SQL
statement that is run on the NotInList event. At the end of the event,
I set Response = acDataErrAdded, telling access that the NewData
variable has been added to the underlying table. The recoord gets
added to the underlying table just fine. The problem is, after the
NotInList event, the afterupdate event is called by access. This is
also no problem. But after...
| |
by: Mark |
last post by:
Hello.
I have a listbox whose rowsource is set to a saved query (call it
"qry_customer_list.") When I add customers to my database, I call the
listbox Requery method so that the listbox will display the customers that I
added. Unfortunately, the listbox display does not change. If I close the
form and reload it, then the listbox will show the new customers.
Any suggestions on how to fix this?
|
by: imrosie |
last post by:
Hello (from Rosie the newbie),
I recently got help with a wonderful event to perform this from 'thescripts'...it recognizes that a name is not in the list an allows for (after parsing first and last name) for the addition of the new FullName into the Customer table. I've been working on some other forms in this application and hadn't noticed until now a little problem.
The event occurs in a 'search customer' form. You first search an...
|
by: FireMedic |
last post by:
Hello all,
I am creating an application that has an equipment inventory and maintenance form that has numerous subforms that are displayed depending on the category of equipment selected.
I have two common combo boxes on each subform - "Supplier" and "Manufacturer". I use the following code for the "NotInList" event and it works fine. (This is the version for the "Supplier" cbo)
Public Sub cboSupplier_NotInList(NewData As String,...
|
by: Volker Neurath |
last post by:
Hi all,
I have a Problem with combobox-property "NotInList" and an unbound Form.
The situation:
On my main form i have three comboboxes for data-exchange (here: Names of
distributor, reseller and final customers, the whole database is made
for storing information about quotatations - no, not for quoting itself)
ut the boxes actually may not contain all our distributors and reseller's
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |