473,387 Members | 1,516 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,387 software developers and data experts.

MS Access not in list event

I'm new to Access programming. I followed Microsoft online instructions for the notinlist event. The code goes from an order form combobox client name to a data entry client form when the user selects a client not in the list. After entering the new client info and closing that form, the focus(?) returns to the client-name order form combobox. The new client information does not appear on the list. I have to manually clear the combobox, close and then reopen the order form. The new client information then appears.

When attempting to requery the combo box, an error message appears that the "field must be saved before requerying."

Thanks
Nov 19 '10 #1

✓ answered by TheSmileyCoder

I don't know what the Microsoft example looks like but this is some of my own code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmb_Document_NotInList(NewData As String, Response As Integer)
  2.     If vbYes = MsgBox("The document [" & Me.cmb_Document.Text & "] could not be found." & vbNewLine & "Would you like to register it now?", vbYesNo + vbQuestion) Then
  3.         DoCmd.OpenForm "frm_DocumentRegistration", acNormal, , , acFormAdd, acDialog, Me.cmb_Document.Text & ""
  4.         If IsNull(Me.cmb_Document) Then
  5.             Response = acDataErrContinue
  6.         Else
  7.             Response = acDataErrAdded
  8.         End If
  9.         Else
  10.         Me.cmb_Document = Null
  11.         Response = acDataErrContinue
  12.     End If
  13.  
  14. End Sub
Notice that the form is opened as dialog (Which means that the code following on the next line is not executed until after the dialog is closed!

This is the code from the 2 buttons on the dialog form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_Cancel_Click()
  2.     Me.Undo
  3.     DoCmd.Close
  4.     Screen.ActiveControl.Undo
  5.     Screen.ActiveControl = Null
  6.  
  7. End Sub
If user doesn't want to register document after all, the last 2 lines will clear the field so user doesn't get another not-in-list event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_Save_Click()
  2.     Me.Dirty = False 'Save record
  3.     Dim intKey As Integer
  4.     intKey = Me.tb_KEY_Document 'Record the autonumbered key of the document
  5.     DoCmd.Close 
  6.     Screen.ActiveControl.Undo 'Clear so we dont get errors
  7.     Screen.ActiveControl.Requery 'Refresh list
  8.     Screen.ActiveControl = intKey 'Set to the newly created document
  9. End Sub
The Screen.ActiveControl.Undo will stop the error message you are receiving.


This example is based on a combobox where a primary key is used.For example:
Expand|Select|Wrap|Line Numbers
  1. SELECT tbl_Documents.KEY_Document, tbl_Documents.tx_Document_D3_ID, tbl_Documents.tx_DocumentName FROM tbl_Documents;

3 5319
TheSmileyCoder
2,322 Expert Mod 2GB
I don't know what the Microsoft example looks like but this is some of my own code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmb_Document_NotInList(NewData As String, Response As Integer)
  2.     If vbYes = MsgBox("The document [" & Me.cmb_Document.Text & "] could not be found." & vbNewLine & "Would you like to register it now?", vbYesNo + vbQuestion) Then
  3.         DoCmd.OpenForm "frm_DocumentRegistration", acNormal, , , acFormAdd, acDialog, Me.cmb_Document.Text & ""
  4.         If IsNull(Me.cmb_Document) Then
  5.             Response = acDataErrContinue
  6.         Else
  7.             Response = acDataErrAdded
  8.         End If
  9.         Else
  10.         Me.cmb_Document = Null
  11.         Response = acDataErrContinue
  12.     End If
  13.  
  14. End Sub
Notice that the form is opened as dialog (Which means that the code following on the next line is not executed until after the dialog is closed!

This is the code from the 2 buttons on the dialog form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_Cancel_Click()
  2.     Me.Undo
  3.     DoCmd.Close
  4.     Screen.ActiveControl.Undo
  5.     Screen.ActiveControl = Null
  6.  
  7. End Sub
If user doesn't want to register document after all, the last 2 lines will clear the field so user doesn't get another not-in-list event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_Save_Click()
  2.     Me.Dirty = False 'Save record
  3.     Dim intKey As Integer
  4.     intKey = Me.tb_KEY_Document 'Record the autonumbered key of the document
  5.     DoCmd.Close 
  6.     Screen.ActiveControl.Undo 'Clear so we dont get errors
  7.     Screen.ActiveControl.Requery 'Refresh list
  8.     Screen.ActiveControl = intKey 'Set to the newly created document
  9. End Sub
The Screen.ActiveControl.Undo will stop the error message you are receiving.


This example is based on a combobox where a primary key is used.For example:
Expand|Select|Wrap|Line Numbers
  1. SELECT tbl_Documents.KEY_Document, tbl_Documents.tx_Document_D3_ID, tbl_Documents.tx_DocumentName FROM tbl_Documents;
Nov 19 '10 #2
Thank you very much!! It was the "undo" action that did the trick. Once the combobox was cleared, the order-entry form could be requeried with the updated client information. I'm learning that Access is very powerful but also very quirky. Thanks again.
Nov 19 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Happy to help. Welcome to Bytes
Nov 19 '10 #4

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

Similar topics

1
by: Todd | last post by:
My form contains a combo box and the "not in list" event is triggerred when the user enters a value that is not among the values listed in the combo box. I want the user to be able to add a new...
2
by: ital1 | last post by:
Hi I have created one form that has an event handler, coded in the following lines : (ON FORM1 : Picture Boxes, when clicked they fire events) this.OnPADClick += new...
29
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ...
0
by: BeccyBoo | last post by:
This has probably been posted before but i've searched and couldn't find the answer I'm looking for (or just couldn't understand it) but here's what i'm trying to do: i have a table...
1
by: Kay | last post by:
Hello, I am trying to write to the event log from my asp.net application but I get a System.Security.SecurityException exception with the message "Requested registry access is not allowed."...
3
by: Brian Graham | last post by:
I have a combo box with a query for a list of names etc. The table has 250,000 rows. The query returns 250,000 rows. But the list returns only 97,000 rows and then shows blank columns after that, so...
1
by: Jason Northampton | last post by:
Hello This is the first time I've used a discusion forum and up until now I have managed to use and or modify VB code from the various sites on the web, until now! This is a simple problem and I...
1
by: rajhbaalaji | last post by:
hi.. i am working in asp.net 2.0 version, i met a problem when i was working in data grid. In project, i have used dropdown list as column in datagrid. i need to fire dropdown list selected index...
2
by: binui | last post by:
I have a data entry form in which there are two synchronized combo boxes - facility and line. Facility is a read only field and the data comes from a global variable which i had set while the user...
3
by: kuki | last post by:
I have created an application where i have 2 windows forms.form1 and form2. there is data in list<> in form1.and now i want to access that information in form2.can i access the list<> in form2?and...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.