Solved

Select a component of subform on ACCESS

Posted on 2011-09-08
3
306 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

820 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