Results 1 to 4 of 4
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Not In List event help

    Hi all,
    I am trying to create a not in list event where it puts the value of a combo box and the new data into the table.
    Getting error 3061 (too few parameters)
    Just not sure how to write this...


    I want to put the value of the CboCatagory (ID#) and the new data into CatagorySubTbl when an item is added to the list that is not currently in the list.
    My belief is its in my string but just need some help crossing the finish line here please...

    Code:
    Private Sub CboCatagorySub_NotInList(NewData As String, Response As Integer)
    Dim strsql As String, x As Integer
    x = MsgBox("Sub Catagory is Not in Current List, Would you Like to Add?", vbYesNo)
    If x = vbYes Then
        strsql = "INSERT INTO CatagorySubTbl (CatagoryID, CatagorySubName) " & _
            "VALUES (" & CboCatagory & ", " & NewData & ")"
        'MsgBox strsql
       CurrentDb.Execute strsql, dbFailOnError
        Response = acDataErrAdded
    Else
        Response = acDataErrContinue
    End If
    End Sub

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    NewData is a string so maybe (wrapped in single quotes):
    Code:
    strsql = "INSERT INTO CatagorySubTbl (CatagoryID, CatagorySubName) " & _
            "VALUES (" & CboCatagory & ", '" & NewData & "')"
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,912
    Is NewData a string?
    Here is my one and only NotInList event
    Code:
    Private Sub Crew_ID_NotInList(NewData As String, Response As Integer)
    'Dim strSurname As String
    'NewData = Left(NewData, InStr(NewData, " ") - 1)
    'Response = AddNewToList(mixed_case(NewData), "Crew", "Surname", "Crews", "frmCrew")
        Dim txtSurname As String, txtInitials As String, strPKField As String
        Dim intNewID As Long
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim strSQL As String
    
        Response = acDataErrContinue
    
        If MsgBox(NewData & " is not in list. Add it?", vbYesNo) = vbYes Then
    
            strSQL = "SELECT * from  Crew WHERE 1 = 0"
            Set db = CurrentDb()
            Set rs = db.OpenRecordset(strSQL)
            txtSurname = Left(mixed_case(NewData), InStr(1, NewData, " ") - 1)
            txtInitials = UCase(Trim(Mid(NewData, InStr(1, NewData, " ") + 1)))
    
            rs.AddNew
            rs!Surname = txtSurname
            rs!Initials = txtInitials
            strPKField = rs(0).Name                  'Find name of Primary Key (ID) Field
            rs.Update
    
            rs.Move 0, rs.LastModified
            intNewID = rs(strPKField)
    
            'DoCmd.OpenForm strNewForm, , , strPKField & "=" & intNewID
            
            Response = acDataErrAdded
    MyExit:
            rs.Close
            Set rs = Nothing
            Set db = Nothing
        Else
            Response = acDataErrDisplay
        End If
    End Sub

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thank you so much~
    Worked like a charm!~
    Dave

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

Similar Threads

  1. Not in list event and spelling errors
    By moke123 in forum Modules
    Replies: 1
    Last Post: 12-27-2019, 12:54 PM
  2. Replies: 4
    Last Post: 10-03-2015, 01:22 AM
  3. Not In List Event Question?
    By mrmims in forum Programming
    Replies: 3
    Last Post: 07-23-2014, 05:49 AM
  4. List Box Click Event
    By bginhb in forum Forms
    Replies: 3
    Last Post: 04-09-2012, 02:06 PM
  5. Not In List event not working
    By Bruce in forum Forms
    Replies: 1
    Last Post: 03-12-2010, 02:24 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