472,958 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

sql statement as a control source in Access reports

Hi everyone,

I am trying to use the expression builder to create input to a control
in an Access report.

I have a table called Records and I want to select the minimum date for
a record where the student = studentID..

The sql is pretty simple: "Select MIN(RecDate) from records_T where
studentID = 1".

Now, I have been trying to get this statement to work with the
expression builder, but no go!!

Is it possible to get this working someho with the expression builder
or supplying the SQL directly to the control source property??

Thanks,
Anja

Dec 7 '06 #1
4 18691
SQL cannot be used as Control Source; it can be used as Record Source for a
Form or Report, and a Field in the Record Source used as Control Source. A
Control Source may also be an expression, a constant, or a Function. The
DMIN Function may provide the information you want... I'd say chances are
slim to none that you actually want to specify the student id as a constant,
so you need to determine how you are going to obtain it... you may well need
to use VBA code to implement what you want.

If you could explain what it is that you have and what you are trying to
accomplish, not how you are trying to accomplish it (e.g., "use the
expression builder to create a control source"), perhaps someone could be
more helpful.

Larry Linson
Microsoft Access MVP
"Anja" <an*******@googlemail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
Hi everyone,

I am trying to use the expression builder to create input to a control
in an Access report.

I have a table called Records and I want to select the minimum date for
a record where the student = studentID..

The sql is pretty simple: "Select MIN(RecDate) from records_T where
studentID = 1".

Now, I have been trying to get this statement to work with the
expression builder, but no go!!

Is it possible to get this working someho with the expression builder
or supplying the SQL directly to the control source property??

Thanks,
Anja

Dec 7 '06 #2

Larry Linson wrote:
SQL cannot be used as Control Source; it can be used as Record Source for a
Form or Report, and a Field in the Record Source used as Control Source. A
Control Source may also be an expression, a constant, or a Function. The
DMIN Function may provide the information you want... I'd say chances are
slim to none that you actually want to specify the student id as a constant,
so you need to determine how you are going to obtain it... you may well need
to use VBA code to implement what you want.

If you could explain what it is that you have and what you are trying to
accomplish, not how you are trying to accomplish it (e.g., "use the
expression builder to create a control source"), perhaps someone could be
more helpful.

Larry Linson
Microsoft Access MVP
"Anja" <an*******@googlemail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
Hi everyone,

I am trying to use the expression builder to create input to a control
in an Access report.

I have a table called Records and I want to select the minimum date for
a record where the student = studentID..

The sql is pretty simple: "Select MIN(RecDate) from records_T where
studentID = 1".

Now, I have been trying to get this statement to work with the
expression builder, but no go!!

Is it possible to get this working someho with the expression builder
or supplying the SQL directly to the control source property??

Thanks,
Anja
Thanks for the reply. Well, I tried using the DLookup function and it
does not give me any errors. However, the date field that it is
supposed to return is formatted as some scientific expression!

So, my statement is:

=CStr(DLookUp(Min("[RecDate]"),"[Records_T]","[Student]=" &
Forms![Student Manager]!MM_GradesByStudent))

Dec 7 '06 #3

Anja wrote:
Larry Linson wrote:
SQL cannot be used as Control Source; it can be used as Record Source for a
Form or Report, and a Field in the Record Source used as Control Source. A
Control Source may also be an expression, a constant, or a Function. The
DMIN Function may provide the information you want... I'd say chances are
slim to none that you actually want to specify the student id as a constant,
so you need to determine how you are going to obtain it... you may well need
to use VBA code to implement what you want.

If you could explain what it is that you have and what you are trying to
accomplish, not how you are trying to accomplish it (e.g., "use the
expression builder to create a control source"), perhaps someone could be
more helpful.

Larry Linson
Microsoft Access MVP
"Anja" <an*******@googlemail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
Hi everyone,
>
I am trying to use the expression builder to create input to a control
in an Access report.
>
I have a table called Records and I want to select the minimum date for
a record where the student = studentID..
>
The sql is pretty simple: "Select MIN(RecDate) from records_T where
studentID = 1".
>
Now, I have been trying to get this statement to work with the
expression builder, but no go!!
>
Is it possible to get this working someho with the expression builder
or supplying the SQL directly to the control source property??
>
Thanks,
Anja
>

Thanks for the reply. Well, I tried using the DLookup function and it
does not give me any errors. However, the date field that it is
supposed to return is formatted as some scientific expression!

So, my statement is:

=CStr(DLookUp(Min("[RecDate]"),"[Records_T]","[Student]=" &
Forms![Student Manager]!MM_GradesByStudent))
A bit more progress:

yet a bit more!

=CStr(CDate((DLookUp(Min("[StuDate]"),"[Records_T]","[Student]=" &

Forms![Student Manager]!SM_GradesByStudent)))

always returns 00:00::05!!

Anja

Dec 7 '06 #4
I'm not sure what I wrote that was unclear, but I do not see the DMin
function that I suggested in either of your followups.

The following Control Source works nicely to return the earliest order for
the customer selected in "cboCustomerID" on a Form whose RecordSource is the
Orders table from the Northwind sample database. The CustomerID in the
Orders table is a text Field, which is why the value must be in quotes in
the DMin statement.

=DMin("OrderDate","Orders","CustomerID = """ & [cboCustomerID] & """")

The DMin domain aggregate function has the purpose of finding and returning
the minimum value of a Field in a Domain -- see the Help. And if this fills
your needs, you don't need to explain what it is that you are trying to
accomplish, so we might suggest alternative approaches.

Larry Linson
Microsoft Access MVP
"Anja" <an*******@googlemail.comwrote in message
news:11*********************@n67g2000cwd.googlegro ups.com...
>
Anja wrote:
>Larry Linson wrote:
SQL cannot be used as Control Source; it can be used as Record Source
for a
Form or Report, and a Field in the Record Source used as Control
Source. A
Control Source may also be an expression, a constant, or a Function.
The
DMIN Function may provide the information you want... I'd say chances
are
slim to none that you actually want to specify the student id as a
constant,
so you need to determine how you are going to obtain it... you may well
need
to use VBA code to implement what you want.

If you could explain what it is that you have and what you are trying
to
accomplish, not how you are trying to accomplish it (e.g., "use the
expression builder to create a control source"), perhaps someone could
be
more helpful.

Larry Linson
Microsoft Access MVP
"Anja" <an*******@googlemail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
Hi everyone,

I am trying to use the expression builder to create input to a
control
in an Access report.

I have a table called Records and I want to select the minimum date
for
a record where the student = studentID..

The sql is pretty simple: "Select MIN(RecDate) from records_T where
studentID = 1".

Now, I have been trying to get this statement to work with the
expression builder, but no go!!

Is it possible to get this working someho with the expression builder
or supplying the SQL directly to the control source property??

Thanks,
Anja

Thanks for the reply. Well, I tried using the DLookup function and it
does not give me any errors. However, the date field that it is
supposed to return is formatted as some scientific expression!

So, my statement is:

=CStr(DLookUp(Min("[RecDate]"),"[Records_T]","[Student]=" &
Forms![Student Manager]!MM_GradesByStudent))

A bit more progress:

yet a bit more!

=CStr(CDate((DLookUp(Min("[StuDate]"),"[Records_T]","[Student]=" &

Forms![Student Manager]!SM_GradesByStudent)))

always returns 00:00::05!!

Anja

Dec 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
4
by: kathy | last post by:
Working in a form, I have an Iif statement where if a date is not filled in, another field will show as a blank. If the date IS filled in, the 2nd field will show its actual value. The following...
2
by: Richard Holliingsworth | last post by:
Hello: How do you attac an SQL statement to an unbound forms (or reports) control in A2002? I created an unbound text box, and I want to attach the following SQL statement..... select...
2
by: tom.darci | last post by:
Hi All, We are hoping to setup source control for our Access XP development. We don't want to use Visual SourceSafe because (a) we often work remotely and (b) we hear bad things about...
2
by: bill | last post by:
I have the following user control in my project simply for setting focus to a control: Public Class SetFocus Inherits System.Web.UI.UserControl
14
by: MLH | last post by:
I use A97. I've gotten used to reading values from textbox controls on forms, I've come to rely on it pretty heavily. My habit spills over into reports. I'm uncertain whether I can reliably read...
2
by: Newbie | last post by:
I have a combobox on a form. Coming from VB, I like to build a dynamic SQL statement and then set the control's data source to the SQL statement. Please tell me how to do that in access using...
1
by: mycall | last post by:
Heyyas. I am trying to print out a report which lists account details and payment amounts from january to december. I have following tables: Payment(paymentNo, DateOwing, amount, accountID)...
0
by: angi35 | last post by:
In Access 2000, I'm trying to create a couple reports but can't figure out the queries. 1. In a form, I have a control with a dollar amount, with the source field . Then there's an option group...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.