textbox used to search and add if not there

cliff7376

Registered User.
Local time
Today, 11:51
Joined
Oct 10, 2001
Messages
107
i would like to be able to type in the record number in the record field and have the record come up. If the record is not there I would like to ask the user if they want to create a new record. I know you can use the find button associated with access but my clients don't like it. I also really don't want a separate search box. Is this possible

help
 
Why not use the combobox wizard to have a combo box list the records available and then pull up the record selected (I will assume a combo box name of cboRecordNumber). Set the Limit to List property to true.

On the NotInList event for the combobox, place code to offer the user to add a record if it doesn't exist. For example:


Dim CR As String

CR = Chr$(13)

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

' Confirm that the user wants to add the new record

Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it? "
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
' If the user chose not to add a record, set the Response
' argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Select another record.", vbOKOnly, "Record Not Added"
Else
' If the user chooses to add a new record, open the Add Record Form
'also set the response argument to suppress the error message

Response = acDataErrContinue

DoCmd.OpenForm "frmYourFormNametoAddArecord", acNormal, , , acFormAdd
Forms!frmYourFormNametoAddArecord!YourFieldName = NewData

Me.cboRecordNumber.Value = 0



End If


HTH
E
 
How could you tweak this to use a text box instead of a combo box? I want the user to be able to type in an account number, and if the account number is not entered, then an add account dialog would open.
 

Users who are viewing this thread

Back
Top Bottom