Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Select a component of subform on ACCESS

Posted on 2011-09-08
3
Medium Priority
?
334 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 500 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

730 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