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 May 4th, 2006, 09:21 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding data when using cascading lists

Hi,

I have a question about how to handle cascading list when data is not in the list and should be added automatically.

Let's say I have a table 'A' with the fields 'B' = car brands and 'C'= car model. The table looks like:
     [u]B</u> [u]C</u>
   Audi A4
   Audi A6
   Volkswagen Golf
   Dodge Viper

this data go in a second table 'D' with the fields 'E' = date, 'F' = Car brand (is the data 'B' from table 'A'), 'G' = car model (is the data 'C' from table 'A') and 'H' = licence plate number.

A form is made out of this second table with a combo box for the 'car brand' and 'car model' fields. I know how I can get the 'car model' combo box only to display the models where the combo box data of the form matches the table 'A' field 'B' brand.

What I would like to know is how I can get a message box to ask me if I want to add a new brand-model combination in the table 'A' if such a record does not exist untill now, when I add some data on the form. This question should be asked when the user wants to close the form or go to the next record. I guess the first thing to do is set the limit-to-list property for the combo boxes to 'NO'.

I'm already using something like this for another table that only has 1 field (and where the limit-to-list property is set on yes). The code I'm using there is the not in list event:

Private Sub Naam_personeelslid_NotInList(NewData As String, Response As Integer)
    On Error GoTo Naam_personeelslid_NotInList_Err
    Dim intantwoord As Integer
    Dim strsql As String
    intantwoord = MsgBox("Het personeelslid " & Chr(34) & NewData & _
        Chr(34) & " staat nog niet in de lijst." & vbCrLf & _
        "Wenst U deze persoon toe te voegen?" _
        , vbQuestion + vbYesNo, "Ongeldige invoer personeelslid")
    If intantwoord = vbYes Then
        strsql = "insert into tblPersoneelsledenIKEA([Naam personeelslid]) " & _
            "values ('" & NewData & "');"
        DoCmd.SetWarnings False
        DoCmd.RunSQL strsql
        DoCmd.SetWarnings True
        MsgBox "Het personeelslid werd toegevoegd aan de lijst." _
            , vbInformation, "Personeelslid toegevoegd"
        Response = acDataErrAdded
    Else
        MsgBox "Gelieve een personeelslid uit de lijst te kiezen." _
                , vbExclamation, "Ongeldige invoer personeelslid"
        Response = acDataErrContinue
    End If
Naam_personeelslid_NotInList_exit:
    Exit Sub
Naam_personeelslid_NotInList_Err:
    MsgBox Err.Description, vbCritical, "Fout"
    Resume Naam_personeelslid_NotInList_exit
End Sub

This works fine If the table only has 1 field. Where do I need to change the code if I want this addition to work with these cascading list?

Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding data to access pchess36 ASP.NET 1.0 and 1.1 Basics 1 December 1st, 2006 06:10 PM
Cascading Lists Problem Brendan Bartley Access 5 October 4th, 2006 12:28 PM
Help adding a row to a data table. jbenson001 VB.NET 2002/2003 Basics 3 March 30th, 2005 02:12 PM
Cascading combo lists in continuous forms rjd97c Access 1 June 30th, 2004 02:51 PM
Adding data to a Database g_dub96 VB.NET 2002/2003 Basics 2 October 8th, 2003 08:18 PM





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