?
Solved

Add Records "on-the-fly"?

Posted on 2004-08-05
8
Medium Priority
?
424 Views
Last Modified: 2012-05-05
I am creating a form for an Invoice database table. One of the fields is CustomerID. This field is a lookup into a Customer database table. It successfully does the lookup based on the CustomerID (autoincrement), and displays the Customer name.

Currently, one may enter only customers that exist in the Customer database table.

I now need to provide the ability to enter a Customer that does not exist in the customer table, and for that customer to automatically be inserted into the Customer table.

Note also that currently, only the Customer name is displayed. If I do provide this "add-on-the-fly" ability, I will need to provide the ability for them to enter the other fields for the Customer record. Is there any easy way for these fields to popup only for this "add-on-the-fly" situation?

So what I need to happen is this:
a. If they are entering an existing customer, then they need only indicate the ID (or name, actually, since that is what they see);
b. If they are entering a new customer, then they need to enter all the customer fields, and this record will be added to the customer database.

How is this implemented? Should this be a sub-form? Any assistance would be welcome. Since I am an MS Access newbie, the more detail, the better.

Thank you.
0
Comment
Question by:yisraelharris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Expert Comment

by:dannywareham
ID: 11724287
If you create a form and bind it to your customer details table, you can enter a new record direct from there.
Be carefull that you protect your form with some security though as it means giving users the ability to manipulate the table data.

Are there any fields in the table that autopopulate? (autonumber for ID for example?)
0
 

Author Comment

by:yisraelharris
ID: 11724493
Hi. Thank you. I am not sure what you mean.

You write:

1. "Create a form" -- you mean a separate form for the customer fields?

2. "bind it to your customer details table" -- You mean that this form I create updates records in the customer database table?

3. "You may enter a new record direct from there" -- what does this part mean?
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 11724537
OK. Create a form first.
Go to your forms area of the db and click NEW.
A wizard will appear.
In the dropdown box, select the table that you want to enter details into through the form.
Click OK.
A blank form will appear with a list of all of your fields.
Add these to your form.
Run the form - you will see the first record in your table shown in the textboxes on your form.
Cycle through the records by clicking the arrows (record navigators) at the bottom of the screen.

As it stands, if you type into the boxes, you will change the data in the table.
So, go back to design view and right click on the form (square at top left)
Select properties
Select events
Go to on load then code builder
A white window will appear - this is the VBA window
Add the following code:

docmd.GoToRecord ,,acNewRec

Close the window
Now run the form
It will automatically take you to a new record ready to add a new customer
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:yisraelharris
ID: 11724894
I am very grateful for your lengthy response but I have totally lost you.

You outlined the details of how to create a from. This I do know how to do. After all, I already have the Invoice form working.

The more I think about it, the more I realize that I don't really see what your response has to do with my original question at all. Can you please re-read it? I think we may be no longer talking about the same topic anymore.

I am not sure what else to say.
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 11724916
I see what you mean.

I see that you have a form working to view old customers - do you want all users to be able to enter a new customer?
If so, create a button on your existing form that opens the form I've described building.
On the form I described, add a button to save the record and close the form.
Now in the orginal form the user will be able to access the new customer.

0
 
LVL 12

Accepted Solution

by:
Sayedaziz earned 150 total points
ID: 11725150
Check with the following if suits and modify the field name as per urs :

Private Sub customerid_DblClick(Cancel As Integer)
    On Error GoTo Err_CustomerID_DblClick
     Dim lngCustomerID As Long
   
     DoCmd.OpenForm "customer", acNormal, , , acFormEdit, acDialog, "GotoNew"
     Me![customerid].Requery
   
     If lngCustomerID <> 0 Then Me![customerid] = lngCustomerID

Exit_CustomerID_DblClick:
    Exit Sub

Err_CustomerID_DblClick:
    MsgBox Err.Description
    Resume Exit_CustomerID_DblClick

End Sub
~~~~~~~~~~~~~~~

Private Sub customerid_NotInList(NewData As String, Response As Integer)
 Me.customerid.Undo
 MsgBox "Double-click this field to add an entry to the list."
 Response = acDataErrContinue
End Sub
0
 

Author Comment

by:yisraelharris
ID: 11725199
Thank you, Sayedaziz.

I want to make sure I understand this:

You are suggesting that I make a separate customer form, which they can get to if they need to by double-clicking on the customerID?

Sounds promising. I will run it by my supervisor.

There were a couple of lines I didn't understand. What do they mean?

1. I didn't see where lngCustomerID gets assigned a value.
2. Me.customerid.Undo
3. Response = acDataErrContinue
0
 
LVL 12

Expert Comment

by:Sayedaziz
ID: 11728844
Here is the details :

1. For your purpose u don't need lngcustomerid , since i have extracted codes from  
    my programme and forget to remove this.

2. Me.customerid.Undo will clear the data entered by users which is not available in the list.

3. Response = acDataErrContinue will supress access default error message of Not in List.

0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question