Solved

Select a component of subform on ACCESS

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now