Find Record OR Create New

James Tebb

New Member
Joined
Nov 12, 2009
Messages
26
I have a form 'JOB FORM' on which is a text box 'CLIENT'

I have a table 'CLIENT LIST' which holds all my client details eg'CLIENT NAME'

I have a form 'CLIENT INPUT FORM' that allows me to input their details.

I want to set up a macro (or other method) so that when I type the clients name in the box on the job form and hit ENTER the following happens:-

1- The client input form opens
2- The relevant client record (matching the text box) appears OR If a record does not exist a new record is created with the clients name automatically entered.

Please be gentle -
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Use a combobox not a textbox, then you can restrict the user to only entering/selecting an existing customer.

You can also deal with them not entering something in the list by setting the Limit To List of the combobox to Yes and creating an event like this.
Code:
Option Compare Database

Option Explicit
 
Private Sub Customer_NotInList(NewData As String, Response As Integer)
Dim resp
    
    resp = MsgBox("Customer" & Me.Field1 & " not on list. Do you wish to add them?", vbYesNo)
    
    If resp = vbYes Then
        Response acDataErrAdded
        ' code to add new customer
        Msgbox "New customer - " & NewData & " added."
    End If
    
End Sub
That's the basics, and it should be straightforward to add the new customer.

Don't have any code for that to hand right now but I'll try and post something later.:)
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top