Results 1 to 4 of 4
  1. #1
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192

    VBA Not In List

    Hello, I am using the following code in Not in List Event:

    Private Sub SeedTrader_IDsup1_NotInList(NewData As String, Response As Integer)
    Dim Result
    Dim Msg As String
    Dim CR As String

    CR = Chr$(13)

    If NewData = "" Then Exit Sub

    Msg = "'" & NewData & "' is not in the list." & CR & CR
    Msg = Msg & "Do you want to add it?"
    If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
    DoCmd.OpenForm "SeedTraderForm", , , , acAdd, acDialog, NewData
    End If

    Result = DLookup("[SdTrName]", "tblSeedTrader", _
    "[SdTrName]='" & NewData & "'")
    If IsNull(Result) Then
    Response = acDataErrContinue
    MsgBox "Please try again!"
    Else
    Response = acDataErrAdded
    End If


    End Sub

    The Code repeats two times in a Form (In case the same Trader is also a broker or Agent). Is it possible to create a Function and refer to the control?

    Regards
    Alex

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Instead of writing all this code,
    I just have the property LIMIT IN LIST =TRUE

    if they want to add items, i have a small button,next to the combo box, that opens the table to add items.
    they just click the refresh key on toolbar afterwards.

    eliminates all this code.

  3. #3
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192
    Thanks for the reply.
    However, the list not only has the name of the new trader, also some other fields which can be filled in the 'SeedTraderForm' which pops up. It works fine. But what I want is if the code can be made into a function and called for in the control so that the code need not be repeated. Since another control in the Form has an Agent. The table 'tblSeedTrader' contains several names, which can be Agents also besides a Trader.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    To create a function in VBA, add this inside the form's VBA module:
    Private Function giveitaname(parameters here, such as NewData,...,)
    ....
    End Function

    Run it whenever you want to by:
    Call giveitaname(NewData,...,)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 08-22-2015, 12:30 PM
  2. Replies: 1
    Last Post: 04-21-2014, 08:00 AM
  3. Replies: 15
    Last Post: 11-20-2013, 04:30 PM
  4. Replies: 2
    Last Post: 04-05-2012, 08:39 PM
  5. Replies: 4
    Last Post: 06-16-2011, 09:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums