Using The NotInList Event And Updating Two Fields The Table

Nov 26, 2005

I have a data entry form where country(ies) (there can be more than one for
each project) is/are entered in a sub-form on a tab control. Countries not
listed are entered by the following:

Private Sub CountryName_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim strMsg As String
Dim ctl As Control
Set ctl = Screen.ActiveControl

strMsg = "Country " & NewData & " Is not listed!" & vbCrLf & "Do you want to
add it?"
If MsgBox(strMsg, vbYesNo, "Not listed") = vbYes Then
strSQL = "INSERT INTO tblCOUNTRY (CountryName) "
strSQL = strSQL & "VALUES('" & NewData & "');"
CurrentDb.Execute strSQL
Response = acDataErrAdded
Else
ctl.Undo
Response = acDataErrContinue
End If
End Sub

This works fine. However, if I restrict the country names by a region
selection on the main form (for example if region Africa is selected on the
the African countries are preselected) the NotIn List does not work. Any way to work around this?

Another question, I want the user to select a region (a combo box ) on the
main form and when a new country (using the NotInList event) is entered in the subform both values go into
the same record in tblCountry (which has two fields CountryName and Region).
For example, I enter AFRICA for region on the main form and on the sub-form I enter Malawi which is not listed. I have tried the following:

Private Sub CountryName_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim strMsg As String
Dim ctl As Control
Set ctl = Screen.ActiveControl

strMsg = "Country " & NewData & " Is not listed!" & vbCrLf & "Do you want to
add it?"
If MsgBox(strMsg, vbYesNo, "Not listed") = vbYes Then
strSQL = "INSERT INTO tblCOUNTRY (CountryName, Region) "
strSQL = strSQL & "VALUES('" & NewData & "', FORMS!frmAddPro!Region);"
CurrentDb.Execute strSQL
Response = acDataErrAdded
Else
ctl.Undo
Response = acDataErrContinue
End If
End Sub

But it does not work (Region is the control on the main form named frmAddPro).
Any suggestions would be welcome. Thanks.
Niels

View Replies


ADVERTISEMENT

Data Misnatch In NotInLIst Event

Jul 28, 2005

OK here is what I have:

Table Name: Student
Fields: Auto (Primary Key)
MOI (number)
Name (Text)

I have 2 forms:
1) Student ,which contains student info I have created a combo box in this form for MOI, so whenever I type an MOI ID that have been previously entered I get the student Name, if it's not previously entered I used the NotInList Event, that asks the user if he wants to add the new value in the list if Yes, it will forward him to the second form

2) student_info, which is an entry form the user enters the name of the student and go back to the student form.

The following is the NotInList event code:

Private Sub Combo10_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
Dim CR As String

CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

' Ask the user if he or she wishes to add the new student.
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then

' If the user chose Yes, start the student_info form in data entry
' mode as a dialog form, passing the new MOI in
' NewData to the OpenForm method's OpenArgs argument. The
' OpenArgs argument is used in student_info form's Form_Load event
' procedure.
DoCmd.OpenForm "student_info", , , , acAdd, acDialog, NewData
End If

' Look for the student the user created in the student_info form.
Result = DLookup("[MOI]", "student", _
"[MOI]='" & NewData & "'")
If IsNull(Result) Then

' If the student was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue

' Display a customized message.
MsgBox "Please try again!"
Else

' If the customer was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If


End Sub


The code is working perfectly except for one problem:

When I'm in student_info form to enter the name of new student and I want to go back to the Student Form I have this error message:

data type mismatch in criteria expression


I figured maybe because I'm passing a number field and in the DLookup criteria it assigns the MOI (which is number) to NewData which is String as follow:

DLookup("[MOI]", "student", _
"[MOI]='" & NewData & "'")

Attach it the database for better understanding of my prolem.
Any help will be very much appreicated!

Thanks,
CS.

View 14 Replies View Related

Modules & VBA :: Textbox Not Populated In NotInList Event

Mar 22, 2014

SQL related with Spec combo box:

Code:
SELECT S.Key, S.Spec FROM tblSpecs AS S ORDER BY S.Spec;

NotInList code:

Code:
Private Sub cboSpecs_NotInList(NewData As String, _
Response As Integer) ' MODIFY SPEC ENTRY.
10 Dim db As Database

[Code]....

1) For some reason, txtMessage is not displayed on the form when NotInList is processed. I see it get populated properly in debug mode, but it never gets on the form. But txtMessage gets displayed normally in Add and Delete events.

It seems to do with the way NotInList works because txtMessage is displayed if I use acDataErrContinue. But that's not what I want; it leaves the combobox list open and can't save record if I close the form.

2) DLookup is used to extract the old Spec value to display in the message. I can see the old Spec in debug mode in cboSpec.column, but Listindex is -1 and unusable.

I don't know how to point to the proper record in the list. The only other way I can think of is to loop through the list comparing the Key, and then extract the Spec.

I don't know if it's more efficient to use lookup or loop.

View 4 Replies View Related

Forms :: Requerying Combo Box After NotInList Event

Sep 10, 2014

I have a form with a subform that contains a combobox where I choose companies to add to a project that is on the main form. If the user types in a company name that is not in the database, I run code on the NotInList event that passes the company name using openargs to a company entry form.

After this form is closed, I return to the subform to choose the company name that I just added, only it is not there because I can't figure out where to automatically requery this combobox. My duct tape solution that's working, is a command button that runs this code when clicked:

Code:

Forms!frmProjects_Detail_CSS!ASP_Project.Form!cbocompany.Requery

I have tried putting this code in the OnCurrent, OnFocus, Onclick, OnEnter....etc on the subform and on the combobox itself. So far the only way it requeries is if I use the command button.if you want to see the NotInList code, and the code on my company entry form.

View 5 Replies View Related

Modules & VBA :: Requery Combobox NotInList Event?

Mar 21, 2014

I have a form frm_GlobalSettings with a combobox cmbDescription that finds a record based on the value selected. The row source type for cmbDescription is Table/query, and the row source is a select statement on the form's underlying table.

I want the user to be able to use cmbDescription to add a new record to the form's underlying table. I currently have

Code:

Private Sub cmbDescription_NotInList(NewData As String, Response As Integer)
Dim strTmp As String
'Get confirmation that this is not just a spelling error.
10 On Error GoTo cmbDescription_NotInList_Error
20 strTmp = "Add '" & NewData & "' as a new global setting?"

[code]....

but when a new value is entered this errors on line 70 with "runtime errror 2118 - you must save the current field before you run the requery action".I've tried various ways around this but can't get it to work.

View 2 Replies View Related

Tables :: Updating Table Data In Event Handler

Mar 11, 2013

I am working with MS Access. The database has 2 tables.

-Parent and Student and ParentID is the Primary key as a parent may have multiple Students
-There is a form that lets me add students for a particular parent

One of the fields in the Parent Table is FeeDue. I added a field in the Parent Table called NumOfStudents..What I want to do is as follows: When a student is added on the Student Form, I want fee to be calculated automatically for display AND update the FeeDue field in Parent table. Event handler executed when a student is added (checkbox clicked)

OnClick()
{
Read NumOfStudents from Parent Table

if(student_added = true)
NumOfStudents++
else /* This is to cover student withdrawl*/
NumOfStudents--

if(NUmOfStudents = 1)
Fee= 400
else
Fee = 500
}

student_added check box is on the student form NumOfStudents and FeeDue are fields in Parent

View 1 Replies View Related

Forms :: Updating Fields Via Code Not Updating Table

Dec 16, 2014

I have a form that has combo boxes and text fields (as well as sub forms). There is also a button linked to some code that says'

Private Sub cmdQuote_Click()
'Creates quote date and prints quote
Me.QuoteDate = Now()
Me.cbAgentID.Requery
DoCmd.OpenReport "Quote", acViewPreview, , "BookingID = " & Me.BookingID
End Sub

When the button is pressed the QuoteDate field (it is bound) should be be populated, but unfortunately it is not. I have played with refresh and requery but cannot derive a solution.

View 1 Replies View Related

Tables :: Updating Fields In Multiple Tables Without Onclick Event

Oct 23, 2013

I am working on a database which has two tables used as part of a registration and login process.

I would like a couple of fields from table one to automatically update in table two, once the fields in table one are populated without using an 'on click' event.

The reason I would prefer not to use an onclick is because the completion of the form used to generate the users table does not require any buttons for the data to save.

View 1 Replies View Related

ComboBox Notinlist 2 Fields

Apr 11, 2006

OKay so i have a combobox with 2 fields, City and CityCode. (i.e. Albany, ALBA) I want to be able to type in a new citycode or city so that when it's not in the list the user can add it to the list along with the field that they're not entering which would be city or citycode. Please help! thanks

View 1 Replies View Related

Updating Specific Fields In Table 1 With Fields From Table 2

Jul 6, 2012

I have 2 tables.

Table 1: Master table
Table 2: Temporary table

This is my current process:

Every quarter I run a report that pulls loans that meet specific criteria.I export this report into excel (the loans fall into column A)I add a file number and box number in columns B and C.I import the excel spreadsheet to table 2 (they're linked so I don't need to import, it's automatic)

Now that I have the updated information back into the database (table 2), how can I get this information back into table 1? The excel spreadsheet only contains a few loans that need to be updated in table 1. I have tried creating an update query with both tables linked and use the "update to" field. However, when I tried to run the query, it says I have 0 records updated.

My update query is as follows:

Field: Access Bar Code
Table: Table 1
Update To: [Table 2].[Access Bar Code]

Field: Access Box Number
Table: Table 1
Update To: [Table 2].[Access Box Number]

Basically I'm trying to have the query update specific fields in table 1 based on the information from table 2.

View 1 Replies View Related

Updating Fields In Table

Nov 8, 2004

I have two tables, one is a list of customer details including email addresses and the other a list of customers and email addresses that have unsubscribed from my mailing list.
How can I use the unsubcribe table to update a field in the details table so I know who's unsubscribed?

View 11 Replies View Related

Updating Fields In Table With New Data - Help

Jun 17, 2007

Hello

I have a table with 3 fields:
- ID no (primany key), Time1 and Time2
I have 3 records with ID no 1 to 3.
So my table look like this

ID no: Time1: Time2:
1 [emty] [emty]
2 [emty] [emty]
3 [emty] [emty]

I have an Excel document with the data for field Time1 and another Excel dokument with the data for field Time2. Excel doc1 have 2 colums named ID no and Time1. And Excel doc2 have 2 colums named ID no and Time2.

How do I import/update these data into my table?

I have tried wiht a adding-quiry but it only works if the table is complety emty and only with one Excel doc. Trying the second Excel doc afterwards only makes an error and no fields are updated.:confused:

View 4 Replies View Related

Updating Specific Fields In Table

Dec 9, 2005

Hello everybody. I am new to Access and as such I don’t know how to perform the following. Please help me out.

The project is about a library loan system. I have a database consisting of the following tables: member (MemCode, LName, …), book (BkCode, Title, TotalCopies,…), purchase (PurDate, BkCode, CopiesBought,…) and transaction (MemCode, BkCode, RentalDate,ReturnDate,Returned).

TotalCopies is the total no. of copies there are of the book
CopiesBought is the number of copies that have been purchased
RentalDate is the date on which book is being loaned
ReturnDate is the last date on which the book has to be returned
Returned is a Yes/No field to indicate if the book has been returned

In the library a member can take only one book at a time.

Problem 1:
The library may have several copies of a particular book, but all will have the same code. For example, a book, let’s say Harry Potter 6 has code 97. Initially only 1 copy of the book is purchased. When the librarian sees the book has great demand, he decides to purchase 3 more copies. All the copies will have the same code, i.e., 97. Only the TotalCopies will become 4.

BkCode is Autonumber in book table and Number in Purchase table. Relationship is 1:many.

I have a Purchase form to record details of books being purchased. I have a command button “Book form” that opens the book form when the user clicks on it. He will use it if the book being purchased is not already available in the library. What I want is:

(i)If he opens the book form to fill in details of the book, then when he closes the form I want the book details to automatically appear in the corresponding fields on the Purchase form.
(ii)The CopiesBought will have to be used to update the TotalCopies in the book table. How should I do this?

Problem 2:
When the user wants to record a loan, the system will need to check if that member already has a book which he has not yet returned. If it is so, then the system will need to provide a prompt to inform the user of this and consequently blocks the user from completing the transaction. How do I do this?

Thanking you in advance for your help.

View 2 Replies View Related

Updating Fields And Data On A Linked Table

Nov 14, 2007

Hi everyone,

I was wondering if this is possible to do:

I have a Form that reads from one Linked Table and Updates a Local Table. Is it possible to move the Local Table to the Back End and still be able to append fields and change field names etc?

If anyone can help, that would be greatly appreciated. Thank you in advance.

Bear

View 1 Replies View Related

Updating 1 Table That Updates Multiple Fields

Sep 20, 2006

I've been working on this problme for several weeks, thinking about it for the last month or so, and am at a loss of what to try next. I'm working on a database for my office that tracks all of the permits we have issued. Every year our permit fees increase by the CPI (consumer price index) and the permit fee entry in the table needs to be updated (75 to 80 entries).

Rather than typing them in every year (too many chances for errors) I'd like to be able to update our fee schedule table (8 entries, look up table) and have that table update all of our fee entries in the permit table.

Any ideas of how to go about this? Thank you for your help.

Scott

View 1 Replies View Related

Updating Fields In Access Table Using Data From Excel

Dec 6, 2005

Hello,

Been wondering how I can update fields in my Access database table using data that lies in an excel spreadsheet.
They have a common row ie say account number and other common fields that need to be updated.

thanks

View 1 Replies View Related

Updating Form After Adding Fields To Its Related Table

Apr 25, 2012

I decide to add a new field to its related table. I always wait to create the form until I think my table is complete, but sometimes I just end up needing to add more info. Is there a quick way to update the form to include my new fields?

View 7 Replies View Related

How To Add A Record In A Table Based On NotInList Option In A Form

Jun 23, 2005

I've 2 tables:

customers
-id
-customer_name
-city_id

cities
-id
-city_name

I've a form to create new customers accounts.
The form has a drop-down control listing the cities in the "cities" table.
This drop-down control has a hidden column (id) and a visible column (city_name).
The user can choose a citie from the list and the city id (1st column in the drop-down list)
will be stored in the "city_id" field in the "customers" table.

Problem:

I need to allow users to enter cities not listed in the drop-down control.
When they entrer a new city, I need to create a new record in "cities" table for the new city.

I tried opening a dialog using the NotInList event, and the dialog pops up as espected, but also pops up an ugly msgbox wich says that the typed text isn't a listed item.

Please help :-(

View 1 Replies View Related

Forms :: Updating All Of User Controlled Fields In Customer Table

Sep 23, 2013

I need to create a form that automatically populates Dealer_ID in my Customers table when a user selects Dealership from a dropdown box.

The form is updating all of the user controlled fields in the Customer table as the user inputs the information. I have a separate Dealership table who's Primary Key is Dealer_ID where dealership information (including the dealer name) is stored. A one to many relationship is in place that connects Dealer_ID from the Dealership table to the same field in the Customer table. The user inputting the information will know what the dealership name is but will not know their ID. I need a solution that will allow the user to select a dealership name in the form and auto-populate the Dealer_ID field in the Customer table with the appropriate ID from the Dealership table.

View 1 Replies View Related

Forms :: Label Not Updating After Afterupdate Event

Jul 15, 2014

So I have a bound form with the following onload code:

Code:
'Add the percent completed to lblPercentCompleted by calling the function
Dim Completed As Double

[code]...

This works fine and set the caption and color of a label on this form.On this form I have several (now only a few, but in the end probably 40 controls or so) which will get updated by the user. When any of these controls are updated, I want the label lblpercentCompleted to get updated with the propper caption and color, however I am having trouble doing this.

I have an afterupdate event on each control with the same code as the onload code, however the message box below appears but the label does not update.

Code:
Private Sub TransferDieCutsOn_AfterUpdate()
MsgBox "Updating Label"
'Add the percent completed to lblPercentCompleted by calling the function
Dim Completed As Double

[code]...

View 6 Replies View Related

Modules & VBA :: Text Box Change Event Prevents Updating?

Jun 18, 2013

Currently I have an issue where on of the fields in a userForm will not update. I have tracked down the problem to an update Event procedure

Code:
Private Sub txtRate_Change()
Me.txtSales = Me.txtRate * Me.txtPages
Me.txtGST = Me.txtSales * 0.1
Me.txtTotal_Inv = Me.txtSales + Me.txtGST
End Sub

The idea being, when you update the rate, the Sales/Revenue figure will update based on that rate. For a while this seemed to work fine. but recently , it just will not allow me to update the field txtRate, I cannot understand why. I have now replaced the _Change() event for a _LostFocus() event. but I am not sure that is as reliable, and I am still puzzled / worried as to why the _Change event will not work.I'm on Access 2013, win 7 , using a front end db connected to the back end using linked tables.

View 8 Replies View Related

Forms :: Updating Multiple Text Boxes Under One Event

Mar 16, 2015

How to trigger the below VBA Code under one Change() Event once a selection is made from the only combobox on my form.

Code:
Private Sub cbxAssociate_Change()
Me.txtFIRJuly14.Value = DAvg("FIR_Perc", "tblFIRStats", "[Associate]= '" & Nz([cbxAssociate]) & "'AND [Month] = 'Jul-14'")
Me.txtFIRAugust14.Value = DAvg("FIR_Perc", "tblFIRStats", "[Associate]= '" & Nz([cbxAssociate]) & "'AND [Month] = 'Aug-14'")
Me.txtFIRSeptember14.Value = DAvg("FIR_Perc", "tblFIRStats", "[Associate]= '" & Nz([cbxAssociate]) & "'AND [Month] = 'Sep-14'")

[Code] .....

View 8 Replies View Related

Forms :: Successfully Updating A Combobox Not In List Event

Jun 14, 2015

I have a basic form linked with a subform inside of it. The main form has a list of customers in a combobox and the subform lists all the things they have ordered from us. This all works perfectly fine, I can add data to the list of things ordered and it's ok.

I decided instead of using a whole extra form to add customers I'd just have a not in list event and allow users to add customers through there, bit more intuitive and cut down on forms.

It works to certain extent except one small problem, if I add a customer I have to close and reopen the form to be able to add/remove data from them in the subform. If I leave the form open and try to enter in data in the subform immediately it just shows whatever customer I had last on the combobox and adds it to the last customer as well.

It works perfectly fine if I reopen it so I thought it was some kind of query or update snafu but all the VBA code examples I found don't seem to do anything. Not exactly sure where to go from here.

PHP Code:

Private Sub cboDept_NotInList(NewData As String, Response As Integer)
    Dim oRS As DAO.Recordset, i As Integer, sMsg As String
    Dim oRSClone As DAO.Recordset
    Response = acDataErrContinue
    If MsgBox("Add dept?", vbYesNo) = vbYes Then
        Set oRS = CurrentDb.OpenRecordset("tblDepartments", dbOpenDynaset)

[Code] .....

View 6 Replies View Related

Updating SubForm Fields From Main Form Fields

Jun 20, 2006

Hey Everyone,

I am stuck trying to figure out this problem. I have a main form "frm_tirelog_600" which has 4 combo boxes "cboleg",
"cbocar", "cbopos", "cboserial" on it. The first 3 combo boxes are used as criteria on 1 of 3 subforms that I have.
The fourth combo box "cboserial" is used for the criteria in a query on another subform that I have called "frm_mount_600_subform",
which is independant from the main form, I hope I have explained that clearly enough. What I need to be able to do is
have the subform fill in 3 of the fields on it "leg", "car", "pos" with the value from the 3 combo boxes on my main form. I
can get it to show in the fields but not write to the table. I have searched the forum and have not been able to locate anything
that would work and really need any assistance with this. Im not real strong in the coding department which is where I
beleive this could be done.



I have attached a copy of my DB which I hope will better explain it. Any help would be greatly appreciated

View 8 Replies View Related

Updating FE Fields When Fields Are Deleted From The BE (after DB Split Obvs)

Aug 28, 2006

Hey,

The database I am working on, I split a while ago to give it some security. Now i'm updating a related form, and i'm finding that if I delete and add fields in the BE, the FE fields (being the fields that I need to insert into the form so the data entered propogates to the DB) are not updated.

How do I update the FE?

Thanks.

View 1 Replies View Related

What Event To Use To Get Information From Two Fields

Apr 2, 2014

I have a record that has a field called "PG". Every "PG" has different standards depending on what quarter it is in. There is a field called "Quarter" in the record along with a field called "PC". The "PC" field is the "PG" field plus the "Quarter" field. (all are text fields). I would like the "PC" field to be automatically entered once the other 2 fields have their values. Do I use the formula

[PC] = [PG] + [Quarter]

And do I put that as an event, and if so, which one.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved