Solved

Add Records "on-the-fly"?

Posted on 2004-08-05
8
420 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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 50 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

730 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