Link to home
Start Free TrialLog in
Avatar of PhilipE
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(NewData 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]![cmbClient]

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
Avatar of Bob Scriver
Bob Scriver
Flag of United States of America image

You are making your call from the AfterUpdate event procedure.  I believe that you must move this code to the NotInList event procedure for everthing to work correctly.  For this event procedure to work you must also set the LimitToList property to Yes.

By trying to execute this code from the AfterUpdate event procedure the proper passing of parameter values doesn't occur.

Bob Scriver
Avatar of PhilipE
PhilipE

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???!!!"
ASKER CERTIFIED SOLUTION
Avatar of Bob Scriver
Bob Scriver
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PhilipE

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