473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Calling NotInList event code for multiple forms

FireMedic
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)

[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 2586
puppydogbuddy
1,923 Expert 1GB
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
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
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?...
5
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...
2
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"...
4
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...
11
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...
7
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...
5
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...
1
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...
6
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,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.