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
I don't know what the Microsoft example looks like but this is some of my own code: - Private Sub cmb_Document_NotInList(NewData As String, Response As Integer)
-
If vbYes = MsgBox("The document [" & Me.cmb_Document.Text & "] could not be found." & vbNewLine & "Would you like to register it now?", vbYesNo + vbQuestion) Then
-
DoCmd.OpenForm "frm_DocumentRegistration", acNormal, , , acFormAdd, acDialog, Me.cmb_Document.Text & ""
-
If IsNull(Me.cmb_Document) Then
-
Response = acDataErrContinue
-
Else
-
Response = acDataErrAdded
-
End If
-
Else
-
Me.cmb_Document = Null
-
Response = acDataErrContinue
-
End If
-
-
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: - Private Sub btn_Cancel_Click()
-
Me.Undo
-
DoCmd.Close
-
Screen.ActiveControl.Undo
-
Screen.ActiveControl = Null
-
-
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. -
Private Sub btn_Save_Click()
-
Me.Dirty = False 'Save record
-
Dim intKey As Integer
-
intKey = Me.tb_KEY_Document 'Record the autonumbered key of the document
-
DoCmd.Close
-
Screen.ActiveControl.Undo 'Clear so we dont get errors
-
Screen.ActiveControl.Requery 'Refresh list
-
Screen.ActiveControl = intKey 'Set to the newly created document
-
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: - SELECT tbl_Documents.KEY_Document, tbl_Documents.tx_Document_D3_ID, tbl_Documents.tx_DocumentName FROM tbl_Documents;
3 5319
I don't know what the Microsoft example looks like but this is some of my own code: - Private Sub cmb_Document_NotInList(NewData As String, Response As Integer)
-
If vbYes = MsgBox("The document [" & Me.cmb_Document.Text & "] could not be found." & vbNewLine & "Would you like to register it now?", vbYesNo + vbQuestion) Then
-
DoCmd.OpenForm "frm_DocumentRegistration", acNormal, , , acFormAdd, acDialog, Me.cmb_Document.Text & ""
-
If IsNull(Me.cmb_Document) Then
-
Response = acDataErrContinue
-
Else
-
Response = acDataErrAdded
-
End If
-
Else
-
Me.cmb_Document = Null
-
Response = acDataErrContinue
-
End If
-
-
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: - Private Sub btn_Cancel_Click()
-
Me.Undo
-
DoCmd.Close
-
Screen.ActiveControl.Undo
-
Screen.ActiveControl = Null
-
-
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. -
Private Sub btn_Save_Click()
-
Me.Dirty = False 'Save record
-
Dim intKey As Integer
-
intKey = Me.tb_KEY_Document 'Record the autonumbered key of the document
-
DoCmd.Close
-
Screen.ActiveControl.Undo 'Clear so we dont get errors
-
Screen.ActiveControl.Requery 'Refresh list
-
Screen.ActiveControl = intKey 'Set to the newly created document
-
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: - SELECT tbl_Documents.KEY_Document, tbl_Documents.tx_Document_D3_ID, tbl_Documents.tx_DocumentName FROM tbl_Documents;
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.
Happy to help. Welcome to Bytes Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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"
...
|
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...
|
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."...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |