Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pre-populate form before displaying 1

Status
Not open for further replies.

MacroAlan

Programmer
Dec 4, 2006
134
US
I am trying to pre-populate a combo box before I display the form with the list. Seems like it should be easy. It blows up when I try to call the form; highlighted in Red

Code:
Private Sub cmdCompares_Click()
    Dim RS      As Recordset
    Dim DB      As Database
    Dim SQstr   As String
On Error GoTo cmdCompares_Click_Err
    SQstr = "SELECT DISTINCT dbo_InfraApps.[Application Name] FROM dbo_InfraApps "
    SQstr = SQstr & "ORDER BY dbo_InfraApps.[Application Name];"
    Set DB = CurrentDb
    Set RS = DB.OpenRecordset(SQstr, dbOpenDynaset, dbSeeChanges)
        RS.MoveFirst
        With [COLOR=#A40000]Forms!frmchooseapp.cboapplic[/color]
            Do While Not RS.EOF
                .AddItem RS![Application Name]
                RS.MoveNext
            Loop
        End With
    DoCmd.OpenForm "frmChooseApp", acNormal, "", "", , acNormal
Anybody have the correct syntax for me? Many thanks!


Alan
[smurf]
 

I'm pretty sure you cannot reference an object on a form that isn't open.


Randy
 
Why do you think you can access a control in a the form not yet open ?
I'd set the RowSource property of the combo in the Load event procedure of the form.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Guess I had my languages confused. I think in Excel I CAN populate first.


Alan
[smurf]
 
DoCmd.OpenForm
This is access syntax ...
Did you try my suggestion ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yep, used the suggestion. Remembered that I was calling my SQL statement in the wrong place.

Thanks!

Got it all fixed and my application is running great. [wiggle]


Alan
[smurf]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top