Search before you add

Huw Davies

New Member
Joined
Aug 26, 2005
Messages
20
Can anyone give me some ideas as to how to force a user to search for an existing client, open a form showing that client's record if found, show an empty form for the addition of a new client if not found.

I've tried putting a dummy record as the first record in my client table but my dear users just start typing and keep overwriting it.

Any suggestions gratefully received (the simpler the better - I'm an old man!)

Thanks

Huw
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi Huw,
I'm not sure I have enough info about your setup but you could try this.

I have an application that opens to a form with only a single text box which accepts a fixed length client identifier. I have set the AutoTab property to yes. I have code in the AfterUpdate event of the textbox which opens another form showing the record for the ClientID the user entered.

Your AfterUpdate code chould choose which form to open or which mode to open a form in, add or edit. The text box could be a combo to select an existing client.
 
Upvote 0
Len,
Thanks for this, I'll try this. Could you tell me how do you choose one action if you've found a record or another one if you haven't?

Huw
 
Upvote 0
Hi Huw
Code similar to this should go in the BeforeUpdate event of your search form.
Code:
Dim stDocName As String
Dim stLinkCriteria As String
Dim varLookup As Variant
On Error GoTo Err_TxtAsk_BeforeUpdate
    
varLookup = DLookup("ClientID", "tblClients", "ClientNum = '" & Me.TxtAsk & "'")
    
If IsNull(varLookup) Then                 'client record doesn't exist
    Cancel = True                         'cancel updating this search form
    'Replace this line for a different action other than just telling them
    MsgBox "You've made a typo. No such client number as " & Me.TxtAsk
Else                                      'client record exists 
    stDocName = "frmClientEdit"           'set the name of the form to open
    stLinkCriteria = "ClientNum = '" & Me.TxtAsk & "'"  'say what record to find
    DoCmd.OpenForm stDocName, , , stLinkCriteria        'open the edit form
    DoCmd.Close acForm, "frmSearch", acSaveNo           'close the search form
End If

Exit_TxtAsk_BeforeUpdate:
    Exit Sub
    
Err_TxtAsk_BeforeUpdate:
    MsgBox Err.Description & vbCrLf & "Error Num:" & Err.Number
    Resume Exit_TxtAsk_BeforeUpdate
If you want, rather than tell them about a typo, you could replace the MsgBox line with a statement block similar to the Else clause to open a different form or the same form in add mode .
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,825
Members
449,096
Latest member
Erald

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