[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bump::msaccess

Title:MSACCESS
Moderator:BUMP::HONER
Created:Tue Dec 01 1992
Last Modified:Mon Jun 02 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1661
Total number of notes:6339

219.0. "Help with combo boxes please!" by SHARE::WILLIS () Tue May 25 1993 17:18

T.RTitleUserPersonal
Name
DateLines
219.1SLOVAX::CDRCTY::NICHOLSONContrary To OrdinaryThu May 27 1993 14:005
219.2more combo box helpTIEFLY::VARDAROThu Feb 27 1997 11:2117
    I am trying to create a combo box that performs mulitple tasks and
    I'm not sure if it can be done and was hoping someone might be able to 
    fill me in!
    
    I would like a combo box (I think that is what I want!) to be able to
    look up values on a table that I can pick from, or enter new values and
    place them in the table.  But, if I enter a value that already exists,
    I want to be able to display the other fields in that record on my
    screen.  
    
    The combo box wizard seem to give me all three choices, but I can only
    pick one and I really need them all!  Is there a way to do what I want
    to do???
    
    Thank you!
    
    Nancy
219.3Some hintsNSIC00::KLERKThunderbirds are GoSun Mar 02 1997 15:0968
    
>    I would like a combo box (I think that is what I want!) to be able to
>    look up values on a table that I can pick from
    Base the combobox on a table and use the properties box of the combobox
    to define which column you want to show and/or use. Then use the
    AfterUpdate event to show the remaining data. 
    
>    , or enter new values and    place them in the table.  But, if I enter a value that already exists,
>    I want to be able to display the other fields in that record on my
>   screen.  

    Define the "not in list" event and write an event procedure to handle
    this situation. Below is a copy of the code I used for this to enter
    a new value into a table that had a counter field (that automatically
    created a new unique number) and the combo box displays the 2nd column
    but is based on this counter field (columns = 2, bound to column 1,
    column widths = 0cm;5cm). You could use this code as starting point for
    what it is you want to achieve yourself.
    The combobox_NotInList event simply calls a general function
         handle_NotInList(newvalue, tablename, keyfieldname,
	         	  columnnameofnewvalue)



    Function handle_NotInList(newdata As String, _
                          ByVal strRowSource As String, _
                          ByVal strIdentField As String, _
                          ByVal strFieldName As String) As Boolean
   
   ' Adds an entry to a table that underlies a combobox. The table must
   ' consist of only two fields: a counter field ident and a descriptive
   ' field whose name is passed as strFieldName.
   ' Arguments:  newdata - value to be added to the table
   '             strRowSource - name of table to add entry to
   '             strIdentField - name of counter field
   '             strFieldName - name of field to contain NewData
   ' The NewData field inputs the descriptive text but will provide
   ' upon exit of function the counter value associated with this
   ' description

    Dim db As DATABASE
    Dim rst As Recordset
    
    handle_NotInList = False

    ' Update the source table by adding a new record
    Set db = DBEngine(0)(0)
    Set rst = db.OpenRecordset(strRowSource)
    rst.AddNew
    rst(strFieldName) = newdata
    
    ' return the counter value that Access gave to this new record
    ' and on which column the combobox is bound
    newdata = rst(strIdentField)
    rst.UPDATE
    rst.Close
    handle_NotInList = True

End Function
    
>    The combo box wizard seem to give me all three choices, but I can only
    Try to read up on Access Basic and forget about those wizards (imho).
    They're good for simple things only.
    

  Theo