Wrox Programmer Forums
|
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 December 26th, 2006, 01:10 AM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recordset retrieving Source

I'm trying to create a dynamic form that is built based on a table that is given when the function is called.

The form has Textboxes labeled txtFieldy where y is 0 - 18. My lookup fields always have ID in them and is converted to a combobox. The first ID field is skipped.

My problem is that I need a property that will look at the table fields and return the Lookup or Rowsource, so I can define my combo box in my dynamic form the same way.

Any Ideas?

Function PopulateFields(strTableName As String)

    Const conNumButtons = 9

    DoCmd.OpenForm "frmDynForms", acDesign
    Forms![frmDynForms](lblForm).Caption = strTableName



    For intOption = 1 To conNumButtons
        Forms![frmDynForms]("txtField" & intOption).Visible = False
        Forms![frmDynForms]("lblField" & intOption).Visible = False
    Next intOption

    Set con = Application.CurrentProject.Connection
    stSql = strTableName

    Forms![frmDynForms].Form.RecordSource = strTableName

    Set rs = CreateObject("ADODB.Recordset")
    rs.Open stSql, con, 1 ' 1 = adOpenKeyset
    i2 = 0

    For i2 = 0 To rs.Fields.Count - 1
        Forms![frmDynForms]("txtField" & i2).Visible = True
        Forms![frmDynForms]("lblField" & i2).Visible = True
        Forms![frmDynForms]("lblField" & i2).Caption = rs.Fields(i2).Name

        If InStr(rs.Fields(i2).Name, "ID") > 0 And i2 <> 0 Then
                If Forms![frmDynForms]("txtField" & i2).ControlType = acTextBox Then
                    Forms![frmDynForms]("txtField" & i2).ControlType = acComboBox
                    Forms![frmDynForms]("txtField" & i2).BoundColumn = 1
                    Forms![frmDynForms]("txtField" & i2).ColumnCount = 2
                    'Forms![frmDynForms]("txtField" & i2).ColumnWidths = "0in;1in"
                    'strdan = rs.Fields(i2).Source
                    'MsgBox ("Rowsource = " & strdan)
                End If
        End If
        Forms![frmDynForms]("txtField" & i2).ControlSource = rs.Fields(i2).Name
    Next i2

    DoCmd.Save
    DoCmd.Close

    rs.Close
    Set rs = Nothing
    Set con = Nothing

    DoCmd.OpenForm "frmDynForms", acNormal


End Function

 
Old December 26th, 2006, 10:44 AM
Authorized User
 
Join Date: Dec 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to FalseParadigm
Default

You can make an sql statement with a string so that you can concatenate your variables together. Then, you can make the object.rowsource equal to the sql string - just like you did for your recordset.

--------------------------------
Ben

"It's my way, or the Hemingway."
--------------------------------
 
Old December 26th, 2006, 12:45 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, I would like the VBA code to discover the source of the field source and then set the source of the form combo box.






Similar Threads
Thread Thread Starter Forum Replies Last Post
SSIS :: Reading from XML source into Recordset grrajoo BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 1 January 12th, 2016 07:48 AM
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
ADODB.Recordset (0x800A0CB3)Current Recordset does tks_muthu Classic ASP Databases 0 June 16th, 2005 07:22 AM
VB6 ComboBox Source from Recordset tsehenuk VB Databases Basics 3 April 12th, 2005 04:41 PM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM





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