borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (find a Suite.)Next Topic (Opening USB Port for Printing) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : access recordset
Poster Message
primfran
Level: Protégé

Registered: 03-06-2005
Posts: 5

icon access recordset

I am new to access vba and need help populating a form.

I have a combo box that contains the tables in my database.  

I want the fields on the form to populate with the records from the table the user selects from the combo box.  

I get a variable not defined error on this line

Set rs = CurrentDb.OpenRecordset("Select * from " & cmbMonth.Text)


Can anyone help?

[Edited by primfran on 20-09-2005 at 04:26 PM GMT]

20-09-2005 at 04:11 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: access recordset

Hello. The "Not defined variable" error means that you didn't declare a variable by the Dim instruction, or either you haven't got an object by that specified name. Or rather, you did it, but there's any mistake in the names.

Now, in your OpenRecordset instruction you have two variables: the rs variable and the cmbMonth.Text variable. So you should check these two declarations, answering to the following two questions:
- did you declare a variable by the name "rs", using the instruction "Dim rs As Database" (or "... As DAO.Database", or "... As ADODB.Recordset", or "... As Variant", or else) before trying to open it?
- did you put a control by the name of "cmbMonth" (have a check on control name spelling), owning a "Text" property (say: are you also sure that the control type is ComboBox?) to be read?

Have a check on these points, and let us know.
Hope it helps

____________________________
Real Programmer can count up to 1024 on his fingers

21-09-2005 at 08:31 AM
View Profile Send Email to User Show All Posts | Quote Reply
primfran
Level: Protégé

Registered: 03-06-2005
Posts: 5
icon Re: access recordset

rs is declared as Recordset and cmbMonth is a combo box control on the form.

21-09-2005 at 12:28 PM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 536
icon Re: access recordset

Try changing the Select statement to -
Set rs = CurrentDb.OpenRecordset("Select " & cmbMonth.Text & ".* from " & cmbMonth.Text)



____________________________
multi-tasking - the ability to hang more than one app. at the same time.

21-09-2005 at 03:48 PM
View Profile Send Email to User Show All Posts | Quote Reply
JOHikerTO
Level: Trainee

Registered: 25-10-2005
Posts: 2
icon Re: access recordset

' In the unbound cmbMonth Afterupdate procedure
' Assuming fields bound on form and fields the same in
' all tables.  Can be done with unbound form by assigning
' values fron recordset to Fields on Form.

Private Sub cmbMonth_AfterUpdate()
    Dim ss as string

    Select Case cmbMonth.Column(0)  
    Case 1
         ss = "Select * From tMonth1"
    Case 2
         ss = "Select * From tMonth2"
    End select

    Me.RecordSource = ss
End Sub

26-10-2005 at 05:26 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : access recordset
Previous Topic (find a Suite.)Next Topic (Opening USB Port for Printing) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder