Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 7th, 2008, 07:42 PM
Authorized User
 
Join Date: Mar 2007
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error 2118 from combo box requery

Hi All

I have an unbound form called form1 which has a series of combo boxes on them, for this problem i am trying to allow the user to add data to a combo box via the NotInList Method. i don't wish to just add the new record to the table as there are multiple fields the user shoud fill in so i am opening a second form (if the NotInList occurs) "frmColours" to allow the user to add the new colour.
Problem, when the user add the new data via the frmColours and closes it i get error on the accmdsaverecord code then i get an error 2118 on requery of cboColour, This code work everywhere else in the database, the only difference is this form (Form1) is unbound. I have added my code in this post.

Any Help would be great

Thanks in advance

Darren

Private Sub cboColour_NotInList(NewData As String, Response As Integer)
'Exit this sub if the combo box is cleared

    If NewData = "" Then Exit Sub


    Response = acDataErrContinue
    DoCmd.RunCommand acCmdUndo

        Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
        Msg = Msg & "Do you want to add it?"
        Style = vbYesNo + vbInformation + vbDefaultButton2 ' buttons
        Title = "New Colour!" 'define title

        Response = MsgBox(Msg, Style, Title, Help, Ctxt)
        If Response = vbYes Then ' If Yes Selected
        MyString = "Yes"
        DoCmd.OpenForm "frmColours", acNormal, , , acFormAdd, acDialog
        MsgBox "Select from the your new Colour"
        DoCmd.RunCommand acCmdSaveRecord
        Me.cboColour.Requery
        Else 'If No Selected
        MyString = "No" 'What to do
        MsgBox "Please Select A Colour From the List"


        End If
End Sub

 
Old January 8th, 2008, 01:31 AM
Authorized User
 
Join Date: Mar 2007
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Again,

After a bit more head scratching and cursing i have a solution to which i will post in case anyone else has a simular problem, the full code for the NotInList event is

Private Sub cboColour_NotInList(NewData As String, Response As Integer)
'Exit this sub if the combo box is cleared

    If NewData = "" Then Exit Sub


    Response = acDataErrContinue
    DoCmd.RunCommand acCmdUndo

        Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
        Msg = Msg & "Do you want to add it?"
        Style = vbYesNo + vbInformation + vbDefaultButton2 ' buttons
        Title = "New Colour!" 'define title

        Response = MsgBox(Msg, Style, Title, Help, Ctxt)
        If Response = vbYes Then ' If Yes Selected
        MyString = "Yes"
        DoCmd.OpenForm "frmColours", acNormal, , , acFormAdd, acDialog
        MsgBox "Click the Drop Down List and select you new Colour"

        'Repopulate cboColour and filter list for NewData
        Dim sSubColourSource As String

    sSubColourSource = "SELECT [tblColourCodes].[ColourID],[tblColourCodes].[ColourCode],[tblColourCodes].[ColourDesc] " & _
                        "FROM tblColourCodes " & _
                        "WHERE [ColourDesc] Like '" & NewData & "*'"
    Me.cboColour.RowSource = sSubColourSource


        Else 'If No Selected
        MyString = "No" 'What to do
        MsgBox "Please Select A Colour From the List"


        End If
End Sub


The Bold text is what i added to make it work,

Cheers All

Darren
:D






Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo box to display items from parent combo box Gini Visual Studio 2008 0 June 18th, 2008 12:30 AM
Combo box choice creating filtered combo box stevensj5 Access 11 September 13th, 2007 11:33 AM
Combo Box Error Brendan Bartley Access 5 September 14th, 2005 09:34 AM
Combo Box / VBA Error socoolbrewster Access 2 March 19th, 2005 01:03 PM
List Box Requery/Refresh misterqj Access 6 July 18th, 2003 07:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.