MattLongmuir
Technical User
Hi Team,
Here's the situation:
I have a table called "Company". Within is a p.key: CompanyID, and a text field: CompanyName
I have a form and a combo box. I intend to use the combo box, to pull a list of items from the Company table, but also allow users to enter in a new Company via the combo box.
Here's the code i'm using:
"Option Compare Database
Option Explicit
Private Sub cboCompanyID_NotInList(NewData As String, Response As Integer)
On Error GoTo err_cboCompanyID_NotInList
Dim ctl As Control
Dim strSQL As String
' Return Control object that points to combo box.
Set ctl = Me!cboCompanyID
' Prompt user to verify they wish to add new value.
If MsgBox("Company is not in list. Add it?", vbOKCancel) = vbOK Then
' Set Response argument to indicate that data is being added.
Response = acDataErrAdded
' Add string in NewData argument to Companys table.
NewData = CapitalizeFirst(NewData)
strSQL = " INSERT INTO Company ( CompanyName ) SELECT '" & Proper(NewData) & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
ctl.Value = NewData
DoCmd.SetWarnings True
Else
' If user chooses Cancel, suppress error message and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
exit_cboCompanyID_NotInList:
Exit Sub
err_cboCompanyID_NotInList:
If Err = 2113 Then
Err = 0
Resume Next
Else
MsgBox Str(Err)
MsgBox Err.Description
Resume exit_cboCompanyID_NotInList
End If
End Sub"
Now, whenever i go to put in a new company, i get this message in Access2k's status bar:
"Control can't be edited; it's bound to AutoNumber field 'CompanyID'.
Argh, it's probably something simple, but i can't figure it out.
Can anyone help?
Here's the situation:
I have a table called "Company". Within is a p.key: CompanyID, and a text field: CompanyName
I have a form and a combo box. I intend to use the combo box, to pull a list of items from the Company table, but also allow users to enter in a new Company via the combo box.
Here's the code i'm using:
"Option Compare Database
Option Explicit
Private Sub cboCompanyID_NotInList(NewData As String, Response As Integer)
On Error GoTo err_cboCompanyID_NotInList
Dim ctl As Control
Dim strSQL As String
' Return Control object that points to combo box.
Set ctl = Me!cboCompanyID
' Prompt user to verify they wish to add new value.
If MsgBox("Company is not in list. Add it?", vbOKCancel) = vbOK Then
' Set Response argument to indicate that data is being added.
Response = acDataErrAdded
' Add string in NewData argument to Companys table.
NewData = CapitalizeFirst(NewData)
strSQL = " INSERT INTO Company ( CompanyName ) SELECT '" & Proper(NewData) & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
ctl.Value = NewData
DoCmd.SetWarnings True
Else
' If user chooses Cancel, suppress error message and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
exit_cboCompanyID_NotInList:
Exit Sub
err_cboCompanyID_NotInList:
If Err = 2113 Then
Err = 0
Resume Next
Else
MsgBox Str(Err)
MsgBox Err.Description
Resume exit_cboCompanyID_NotInList
End If
End Sub"
Now, whenever i go to put in a new company, i get this message in Access2k's status bar:
"Control can't be edited; it's bound to AutoNumber field 'CompanyID'.
Argh, it's probably something simple, but i can't figure it out.
Can anyone help?