Solved

Select a component of subform on ACCESS

Posted on 2011-09-08
3
327 Views
Last Modified: 2012-05-12
Hello Experts,

I am currently beginning on Access/VB.
I am working on a formular which includes a list and a subform.
Basically I type year on a textboxt and the subform shows the list of course beginning at this year after cliking on a button. (table course have an ID, description and Year item)
I think it's something like writting in the button click  event function like:
 
"Me.Form .." but i dont know more.

the "algorithm" is simple:

1)get the year from the text box
2)use this for making a sql request in the subform
3)apply!

I have no idea of the syntax even for 1 and i dont know how to apply SQL request to form (after storing it in a String), could you give me some clues?


Thanks !
0
Comment
Question by:Noero
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:Noero
ID: 36509089
obviously you deserve more...
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 36509939
if they are two seperate forms then each would have a name similar to FormMain or frmMain and FormSub or frmSub.  If you did not name them then the automatic naming system would have done that for you with the first one created as Form1 and the second as Form2.  With that latter as an example,

Me.TextBox would be equvalent to Form1.TextBox and so to reach your sub form would be Form2.ObjectName.  If you have made some variables as Public in your sub form you would be able to reach them as well...  From2.VarName

0
 
LVL 11

Accepted Solution

by:
LambertHeenan earned 125 total points
ID: 36512363
From you description it seems that you have a textbox that the user enters a date in. That is on the main form. Then you have a listbox that is on a sub-form of the main form.

So you type a date in a textbox (which you should at least have an input mask defined for so that the user will only be able to enter something that *looks* like a date.) For the sake of discussion let's call it txtDateStart, and I will also assume that the listbox is called "ListBoxCourses", and that the sub-form control is called "sub_form_Courses". Substitute the correct names in your application.

Then you have the command button that the user clicks. The On_Click event of that button will do all the work.

First you would need to validate the "date"

    If Not IsDate(txtStartDate) then
        MsgBox txtStartDate & " is not a valid date."
    Else
    ...
    End If

Assuming the date test is passed, then all the other code you need will be in the Else part of the above If statement.

That code needs to update the data source of the listbox that you have on the sub-form. So first you need to create the SQL string that will be used to retrieve the data, again I will make assumptions about table names and fields names...

In the body of the command button's On_Click event declare a string variable...

Dim strSQL as String

... and in the Else section of the above code you would built the SQL ...

strSQL = "Select Id, Description,YearOffered from tblCourse where YearOffered >=#" & txtDateStart & "#"

Then you need to plug that SQL into the data source of the listbox.

Me.sub_form_Courses.Form.ListBoxCourses.RowSource = strSQL

And that should do it for you.

HTH
Lambert
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question