Solved

Select a component of subform on ACCESS

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

710 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