473,768 Members | 8,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update a value that is NotInList

beacon
579 Contributor
Hi everybody,

I have an Employee table with the following:
Expand|Select|Wrap|Line Numbers
  1. Table - Employee
  2. --------------------------
  3. ID: AutoNum, PK
  4. FName: Text
  5. LName: Text
  6. Status: Yes/No
  7.  
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub EmployeeIDFK_NotInList(NewData As String, Response As Integer)
  2.  
  3.     Dim strEmployeeID As String, strWhere As String
  4.     Dim addToListMessage As String, notInListMessage As String, notInListTitle As String
  5.     Dim notInListUpdate As String, notInListUpdateTitle As String
  6.     Dim previousEmployee As Boolean
  7.     Dim varEmployeeStatus As Integer, varEmployeeID As String
  8.     Dim strUpdate As String
  9.  
  10.     addToListMessage = "The employee ID you entered is undefined." + Chr(13) + Chr(13) + "Do you want to add the employee?"
  11.     notInListMessage = "The employee you selected is not in the list. Please try again."
  12.     notInListTitle = "Employee: Not in List"
  13.     notInListUpdate = "The employee was successfully added."
  14.     notInListUpdateTitle = "List Updated"
  15.  
  16.     strEmployeeID = NewData
  17.  
  18.     strWhere = "[EmployeeID] = " & strEmployeeID
  19.     varEmployeeStatus = -1
  20.  
  21. 'THIS IS THE PART I ADDED TO CHECK FOR AN EXISTING EMPLOYEE
  22. '------------------------------------------------------------------------------------------------------------
  23.     If IsNull(DLookup("EmployeeID", "qryEmployees", strWhere)) Then
  24.         GoTo EmployeeNotInList
  25.     Else
  26.         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
  27.             Response = acDataErrContinue
  28.             strUpdate = "UPDATE qryEmployees " & _
  29.                         "SET EmployeeStatus =" & varEmployeeStatus & " " & _
  30.                         "WHERE [EmployeeID]= " & strEmployeeID & ";"
  31.             DoCmd.RunSQL strUpdate
  32.             '[Forms]![frmDeficiency].deficiencyTabControl.Pages(1).SetFocus
  33.             '[Forms]![frmDeficiency].Requery
  34.             'Me.EmployeeIDFK.Requery
  35.             'Me.EmployeeIDFK.SetFocus
  36.  
  37.             GoTo EmployeeExit
  38.         Else
  39.             MsgBox notInListMessage, vbInformation, notInListTitle
  40.             Me.EmployeeIDFK.Value = Null
  41.             Response = acDataErrContinue
  42.             Exit Sub
  43.         End If
  44.     End If
  45.  
  46. '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
  47. EmployeeNotInList:
  48.     If vbYes = MsgBox(addToListMessage, vbQuestion + vbYesNo, notInListTitle) Then
  49.         Forms!frmDeficiency.Visible = False
  50.         DoCmd.OpenForm "frmEmployeeAddition", DataMode:=acFormAdd, _
  51.             WindowMode:=acDialog, openArgs:=strEmployeeID
  52.         If IsNull(DLookup("EmployeeID", "qryEmployees", strWhere)) Then
  53.             MsgBox notInListMessage, vbInformation, notInListTitle
  54.             Me.EmployeeIDFK.Value = Null
  55.             Response = acDataErrContinue
  56.         Else
  57.             MsgBox notInListUpdate, vbInformation + vbOKOnly, notInListUpdateTitle
  58.             Response = acDataErrAdded
  59.         End If
  60.     Else
  61.         MsgBox notInListMessage, vbInformation, notInListTitle
  62.         Me.EmployeeIDFK.Value = Null
  63.         Response = acDataErrContinue
  64.     End If
  65.  
  66. EmployeeExit:
  67.     Exit Sub
  68.  
  69. End Sub
  70.  
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?
Feb 17 '09 #1
1 1870
beacon
579 Contributor
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... :)-
Feb 17 '09 #2

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

Similar topics

4
2731
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
8
2489
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
1
1354
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?
2
2222
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
3
1197
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...
6
9971
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?
1
1888
imrosie
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...
2
2628
FireMedic
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,...
6
2686
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
0
9576
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, 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...
0
10175
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, 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...
0
10017
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 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...
1
9961
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,...
1
7384
isladogs
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...
0
6656
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();...
0
5283
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...
1
3932
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
2
3534
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.