PhilipE
asked on
Why can't I run this code from a NotInList function??
My problem is this.
I have a number of combo's, all of which require the ability to add an extra record to the table from where the list is generated. I would very much like to do this using a module, but Access seems not to like refering to modules whilst using the NotInList method. Here's the code, what can be done?? Any help greatly appreciated.
PhilipE
Here's the code that appears for each combo box notinlist function
Private Sub cmbComp1_AfterUpdate()
Call CompetitorNotInList
cmbComp2.Enabled = True
End Sub
Here's the module code called by the combo box code.
Public Sub CompetitorNotInList(NewDat a As String, Response As Integer)
Dim sMsg As String
Dim sSQL As String
Dim sClient As String ' New entry for combo box
Dim ctlCurrentControl As Control
'Identifies which combo box has focus
Set ctlCurrentControl = Screen.ActiveControl
sClient = [Forms]![ReputationFrm]![c mbClient]
sMsg = "Do you wish to add entry to the list?"
sSQL = "INSERT INTO CompetitorTbl (ClientName,CompetitorName ) " & _
"VALUES ( '" & sClient & "', '" & NewData & "')"
If MsgBox(sMsg, vbYesNo) = vbYes Then
Response = acDataErrAdded
CurrentDb.Execute (sSQL)
ctlCurrentControl.Undo
ctlCurrentControl.Requery
Else
Response = acDataErrContinue
ctlCurrentControl = ""
End If
End Sub
I have a number of combo's, all of which require the ability to add an extra record to the table from where the list is generated. I would very much like to do this using a module, but Access seems not to like refering to modules whilst using the NotInList method. Here's the code, what can be done?? Any help greatly appreciated.
PhilipE
Here's the code that appears for each combo box notinlist function
Private Sub cmbComp1_AfterUpdate()
Call CompetitorNotInList
cmbComp2.Enabled = True
End Sub
Here's the module code called by the combo box code.
Public Sub CompetitorNotInList(NewDat
Dim sMsg As String
Dim sSQL As String
Dim sClient As String ' New entry for combo box
Dim ctlCurrentControl As Control
'Identifies which combo box has focus
Set ctlCurrentControl = Screen.ActiveControl
sClient = [Forms]![ReputationFrm]![c
sMsg = "Do you wish to add entry to the list?"
sSQL = "INSERT INTO CompetitorTbl (ClientName,CompetitorName
"VALUES ( '" & sClient & "', '" & NewData & "')"
If MsgBox(sMsg, vbYesNo) = vbYes Then
Response = acDataErrAdded
CurrentDb.Execute (sSQL)
ctlCurrentControl.Undo
ctlCurrentControl.Requery
Else
Response = acDataErrContinue
ctlCurrentControl = ""
End If
End Sub
ASKER
I have the limit to list property set to yes, and I have tried to run the call command from the OnNotInList method. It comes up with the following error message:
Compile Error
Argument not Optional
Here's the code . . .
Private Sub cmbComp2_NotInList(NewData As String, Response As Integer)
Call CompetitorNotInList
End Sub
"What's going on???!!!"
Compile Error
Argument not Optional
Here's the code . . .
Private Sub cmbComp2_NotInList(NewData
Call CompetitorNotInList
End Sub
"What's going on???!!!"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works! Would you believe it, that simple. Anyways. Thanks a bunch for that Bob. Top man. Here's your points and take care.
PhilipE
PhilipE
By trying to execute this code from the AfterUpdate event procedure the proper passing of parameter values doesn't occur.
Bob Scriver