Results 1 to 3 of 3
  1. #1
    slow&steady is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    3

    form controls & recordset

    Hi Friends,



    This is my first message to this forum and also i am new to access (forms/programming).So please forgive me if the question is dumb or if it is posted in the wrong forum.

    Now the question:

    I am creating an access app where i have 2 forms.

    Default Form with combobox cb_default

    Main Form with combobox cb_Main and a listbox lst_main

    I have bound the Default form to a recordset and retrived a column of the table into cb_Default.I want to populate the cb_Main from the same recordset according to the value selected in cb_Default and populate lst_main from the same recordset accoording to value selected in cb_main.

    Do i have to bind the recordset to each control because the query is not same for all

    i am little confused

    help me

    thanks in advance

    Sri

  2. #2
    evander is offline Competent Performer
    Windows 7 Access 2003
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    206
    Hello Sri. Welcome to the forum!

    Regarding your question...

    If you're referring to the list items that should populate the combobox and listbox:
    (1) Do not set the record source of the form to the queries that should populate the combobox and listbox.
    (2) Go to the properties of the combobox and set the row source type to Table/Query.
    (3) Set the row source to the name of the query containing the list items for the combo box.

    You can do the same for the listbox.

    Remember, the row source property specifies the list items that should be displayed in a combobox or listbox, while the control source property tells them which field in which table should a selected item get stored.

    Hope this helps. Good luck.

  3. #3
    slow&steady is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    3
    Thanks for the Reply

    But i am still confused

    My code is following

    ********Module1 **************

    Public cnEmpCodes As ADODB.Connection
    Public rsEmpCodes As ADODB.Recordset

    Public Sub Connections( byval dim str as string )
    Set cnEmpCodes = New ADODB.Connection
    Set rsEmpCodes = New ADODB.Recordset

    cnEmpCodes.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
    "Dbq=C:\Access\Employee.mdb;"

    With rsEmpCodes
    Set .ActiveConnection = cnEmpCodes
    .Source = STRSQL
    .LockType = adLockReadOnly
    .CursorType = adOpenKeyset
    .Open
    End With
    End Sub

    ********* Default form *************

    Private Sub Form_Load()

    Dim strSql, strRow As String

    strSql = "SELECT * FROM EmpTable ORDER BY Emp_ID;"

    'Prepare the read only database connections
    Connections strSql

    'Set the form's Recordset property to the ADO recordset
    Set Me.Recordset = Module1.rsEmpCodes

    Do while not rsEmpCodes.EOF
    StrRow=StrRow & rsEmpCodes.Fields("Emp_ID") & ","
    rsEmpCodes .MoveNext
    if rsEmpCodes.EOF then exit do
    Loop
    cb_Default.Rowsource = left(StrRow,len(StrRow)-0)

    End Sub



    ************ Main form ******************

    Private Sub Form_Load()

    Dim strSql, strRow As String

    strSql = "SELECT Distinct Emp_Div FROM EmpTable ORDER BY Emp_Div;"

    'Prepare the read only database connections
    Connections strSql

    'Set the form's Recordset property to the ADO recordset
    Set Me.Recordset = Module1.rsEmpCodes

    Do while not rsEmpCodes.EOF
    StrRow=StrRow & rsEmpCodes.Fields("Emp_Div") & ","
    rsEmpCodes .MoveNext
    if rsEmpCodes.EOF then exit do
    Loop
    cb_Main.Rowsource = left(StrRow,len(StrRow)-0)
    lst_Main.roswource = query \\ where query = "select Emp_Name from EmpTable where Emp_Div =" &cb_Main.text &';'
    End Sub

    if I assign lst_main.rowsource to a query I am getting an error like u misspelled the Databse or datbas not available

    wat to do ?

    Thanks in advance

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

Similar Threads

  1. Font Issue on Form that uses tab controls
    By randolphoralph in forum Forms
    Replies: 1
    Last Post: 06-07-2010, 01:26 PM
  2. Replies: 1
    Last Post: 11-13-2009, 03:03 AM
  3. Replies: 1
    Last Post: 09-28-2009, 05:21 PM
  4. Accessing form controls
    By dante in forum Forms
    Replies: 15
    Last Post: 07-28-2009, 08:26 AM
  5. Adding Controls to a Form
    By msmayhew in forum Programming
    Replies: 7
    Last Post: 12-14-2005, 03:26 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