Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding data to Combo Box using NotInList

Status
Not open for further replies.

Kobe1

MIS
Dec 12, 2002
8
0
0
GB
Hi everyone
I am just learning VB and am trying to put some code in so that employees can be added to the combo box if they are not on the list.

I have put the code in but get an error message "Compile error: Ambigiuos name detected: ClientInputButton_Click" when I try and enter a new employee record.

The form in which the employees are added is based on a query. The control of the combo box is EmployeeID and is a field in a table called "Timesheet". I have a table called Employees with EmployeeID field as the primary key.

Below is the code I put into NotInList event procedure

Private Sub EmployeeID_NotInList(NewData As String, Response As Integer)
' Allows user to add a new employee by typing the employee's name
' in the EmployeeID combo box.

Dim intNewCustomer As Integer, strTitle As String
Dim intMsgDialog As Integer, strMsg As String
Const conClrWhite = 16777215
Const conNormal = 1

' Check if user has already selected an employee.
If IsNull(CustomerID) Then

' Display message box asking if the user wants to add a new employee.
strTitle = "Employee Not in List"
strMsg = "Do you want to add a new employee?"
intMsgDialog = vbYesNo + vbExclamation
intNewEmployee = MsgBox(strMsg, intMsgDialog, strTitle)

If intNewEmployee = vbYes Then

' Remove text user entered from the combo box and assign
' it to the EmployeeID control.
DoCmdDoMenuItem acFormBar, acEdit, acUndoField
EmployeeID.Enabled = True
EmployeeID = NewData

' Enable and move focus to EmployeeID.
EmployeeID.Enabled = True
EmployeeID.Locked = False
EmployeeID.BackColor = conClrWhite
EmployeeID.BorderStyle = conNormal
EmployeeID.SetFocus

MsgBox "Enter the new Employee's."

' Continue without displaying default error message.
Response = acDataErrAdded
Else
' Display the default error message.
Response = acDataErrAdded
End If
Else
' User has already picked an employee; display a message and undo the field.
strMsg = "To modify this customer's company name, edit the name in the "
strMsg = strMsg & "box below the EmployeeID combo box. To add a new employee, "
strMsg = strMsg & "click Undo Record on the Records menu and then type the "
strMsg = strMsg & "new employee name in the EmployeeID combo box."
MsgBox strMsg
DoCmd.DoMenuItem acFormBar, acEdit, acUndoField

' Continue without displaying default error message.
Response = acDataErrAdded
End If
End Sub
End Sub

Can anyone help me?

Thanks in advance
 
The error message that you are getting normally means that there are 2 or more procedures defined with the same name on the same form.

Go to menu Edit/Find and search for 'ClientInputButton_Click' and you willprobably find 2 versions of the procedure - remove the duff one!

On a separate note, you don't need :
Code:
Const conClrWhite = 16777215

as VB has an intrinsic (always available) constant VBWhite which equals 16777215. For the other values, look up Color Constants in VBHelp or Object Browser
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top