473,775 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling NotInList event code for multiple forms

FireMedic
18 New Member
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 "Manufactur er". I use the following code for the "NotInList" event and it works fine. (This is the version for the "Supplier" cbo)

[i]
Expand|Select|Wrap|Line Numbers
  1. [i]Public Sub cboSupplier_NotInList(NewData As String, Response As Integer)
  2. On Error GoTo cboSupplier_NotInList_Err
  3.     Dim intAnswer As Integer
  4.     Dim strSQL As String
  5.  
  6.     intAnswer = MsgBox("The Supplier " & Chr(34) & NewData & _
  7.         Chr(34) & " is not currently listed." & vbCrLf & _
  8.         "Would you like to add it to the list now?" _
  9.         , vbQuestion + vbYesNo, "I-TEAM Utilities")
  10.     If intAnswer = vbYes Then
  11.         strSQL = "INSERT INTO tbl_Suppliers([SupName]) " & _
  12.                  "VALUES ('" & NewData & "');"
  13.         DoCmd.SetWarnings False
  14.         DoCmd.RunSQL strSQL
  15.         DoCmd.SetWarnings True
  16.         MsgBox "The new Supplier has been added to the list." & _
  17.         " Please enter remaining contact information" & vbCrLf & _
  18.         "before proceeding further" _
  19.             , vbInformation, "I-TEAM Utilities"
  20.         Response = acDataErrAdded
  21.         DoCmd.OpenForm "frm_Test2"
  22.     Else
  23.         MsgBox "Please choose a Supplier from the list." _
  24.             , vbInformation, "I-TEAM Utilities"
  25.         Response = acDataErrContinue
  26.     End If
  27. cboSupplier_NotInList_Exit:
  28.     Exit Sub
  29. cboSupplier_NotInList_Err:
  30.     MsgBox Err.Description, vbCritical, "Error"
  31.     Resume cboSupplier_NotInList_Exit
  32.  
  33. End Sub
I would like to include these once as a public function or sub and call them with the NotInList event of each combo box but have had no success in getting this to work. The row source tables are the same for these cbo boxes on all 18 subforms.
Jan 17 '08 #1
2 2629
puppydogbuddy
1,923 Recognized Expert Top Contributor
I have never tried this, but you should be able to get it to work if you add the form object to the sub's arguments as shown. Also, give the sub a slightly different name (g = global) to distinguish from the form's not in list event, which will fire if the limit to list property is set to yes and the item entered is not on the list. Essentially all you are doing is passing the NotInList call from the local to central processing.
Expand|Select|Wrap|Line Numbers
  1. Public Sub gcboSupplier_NotInList(Frm As Form, NewData As String, Response As Integer) 
When the NotInList event is fired for the form, just call the public sub and pass the required parameters.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSupplier_NotInList()
  2. gcboSupplier_NotInList(Me)
  3.  
  4. End Sub
Jan 22 '08 #2
FireMedic
18 New Member
You Sir are a prince among PuppyDogBuddies .

Works like a charm.
Thanks a million
Jan 28 '08 #3

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

Similar topics

3
2810
by: Pieter Linden | last post by:
Just got done reading some of ADH2000 about comboboxes and the NotInList event... Doesn't look like it's possible to tweak the behavior of this so that I can have a non-text bound column, can I? Say I have a Customers--Invoices relationship, and I want to be able to pick the Customer's name from a combobox. (keeps people from entering the same text - or worse, just almost the same - a zillion times). So I create a CustomerID, enforce...
5
1678
by: David Deacon | last post by:
Hi i have the following code in a CustomerID field if the user enters a notinlist customer then they should dbl click to open the customer form However this error occurs "You tried to assign a null value to a varaible that is not a variant type" My code Dim lngCustomerID As Long If IsNull(Me!) Then
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
4
1811
by: CAD Fiend | last post by:
Hello, I have a combo box (cmbFirstName) on a form that is hitting a query (qryFirstName) and then putting that selected (or typed by user) value to the table field (name FirstName) on the table (tblUserInfo). The query hits a look up table called (lulFirstNames). If the user DOESN'T find the name they want in the combo box, they will just type it in.
11
2805
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field (strPubCity) for Publisher City. These two fields have a many-to-one relationship with tables, (tlkpPubName and tlkpPubCity) respectively. The lookup tables only have one field (strPubName and strPubCity), which is their primary key. I also have...
7
6058
by: Bryan | last post by:
I am trying to allow the user to add an item to a list if it is not found in a combobox. When the NotInList event is triggered I run a function "AddItem" that has a custom dialog box to add an item to the underlying table. The function either returns "Not Added", or the new Items ID. I know the function works fine. Whe I try the code below I get errors saying "Close action was cancelled" (referring to my custom popup input box), & ...
5
7853
by: Stinky Pete | last post by:
Hi (again) ;-) I'm still very much at the bottom of a steep learning curve with VB, so any and all help is always appreciated. I've found some code to generate the user names who have logged onto the file in question and from what I've been reading it will do what I need. However, what is eluding me is the "calling" it bit. If anyone can put into simple terms what is needed & general principles I would be really grateful.
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...
6
2687
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
9622
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
10268
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...
1
10048
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,...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
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
5360
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...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.