473,785 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RecordSource OnOpen

I am changing the recorsource in the onopen event of my report simply
using this line :

RecordSource = "SELECT * FROM tbl_Temp_Impres sionQuestionnai re WHERE
Num_Questionnai re = 19"

However how could I pass a parameter defined in another sub to this
onopen code to replace 19 with the number chosen by my user.

Or WHEN can I define the recordsource other than in the onopen event.

I would like to define the recordsource based on a variable in my sub
then open (??) the report.

Thank you

Nov 13 '05 #1
3 1933
you could set the recordsource to the result of a function that
receives the Num_Questionnai re value...

Function MyRowsource (byval lngQuestionID As Long) As String
MyRowsource = "SELECT * FROM tbl_Temp_Impres sionQuestionnai re WHERE
Num_Questionnai re =" & lngQuestionID
End Function

Nov 13 '05 #2
Duh... it's a *report*... forgetting how to read.

Pass the filter in the Open event of the report.

Just Num_Questionnai re = <something>

.... could be Forms!MyOpenFor m!MyTextControl

or some such...

See OpenReport in the help - it gives examples

Nov 13 '05 #3
Patrik:

Is the '19' the only part of your report's recordsource that changes?
If that's the case, and you're opening the report from within another
sub, use the built in feature of the DoCmd.OpenRepor t method to limit
the records it returns in the report. Here's what you can do:

In Design View of the report, set the report's recordsource to "SELECT
* FROM tbl_Temp_Impres sionQuestionnai re" which will be a completely
unfiltered report, and save it. Be sure to comment out the code that
affects the recordsource in your OnOpen event of the report.

In the sub where you're assigning the parameter and opening the report,
do this:

Dim strCriteria as String
strCriteria = "Num_Questionna ire = " & Whatever#YouWan tOnReport

Find the line that says DoCmd.OpenRepor t "YourReportName " and replace
it with:
DoCmd.OpenRepor t "YourReportName ", , , strCriteria

Note that the strCriteria is basically your "WHERE" clause of the SQL,
without the word "WHERE", so you can build this string into whatever
criteria you want. Remember that date criteria will need to be wrapped
with # signs and text with single quotes. Numerical parameters won't
need any wrapping.

HTH,

Jana

Nov 13 '05 #4

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

Similar topics

2
2629
by: ColinWard | last post by:
Hi. I have a form which has as its recordsource an SQL string. The SQL String is as follows: SELECT * from CONTACTS where false. this ensures that there is no data loaded in the form when the form is opened. After the user selects the contact from an unbound combobox I want the form to be rebound to its recordsource. I tried using form.recordsource = "Contacts" in the afterupdate event of
4
2790
by: ColinWard | last post by:
Hi. I use two different pieces of code to manipulate a recordsource for a form. The first one sets the recordsource to null when the form loads. The second is supposed to display the corresponding record when a name is selected from a combobox. ---Code start---- Private Sub Form_Load() If Not Me.FilterOn Then 'If filter is on, then this form was opened from
3
3859
by: Martin Austin | last post by:
Here's my problem. I'm launching an MS Word object on a Notes document Postopen event. The script kicks off a macro that saves the Word document to a temporary file every n minutes (backup of key data). This works fine apart from Notes kind of hangs because it is waiting on the macro to finish. This never happens because the macro is using timer code to save every n minutes. The solution sounds simple, start the macro on the Word...
32
3699
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's RecordSource like this? Am I asking for trouble doing this with a memo field? Thanks in advance. Private Sub cmdNextNote_Click() Dim lngNid As Long If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
1
4775
by: Jimmy Stewart | last post by:
I have a continuous form with a list of items from a table. One of the fields in the table is "print". this allows the user to select items from the list on the form for printing in a report. on that form i have a button with the following onclick event: DoCmd.OpenReport "rptCustomerReport", acViewPreview, , "Print = True" This opens the report "rptCustomerReport" and shows all of the records that the user had checked of on the form....
2
2334
by: G Gerard | last post by:
Hello I have noticed that whenever I set a form's RecordSource property in code it launches the form's OnActivate event. In one of my application I set a form's RecordSource to zero lenght string during the form's OnClose event Private Sub Form_Close()
3
2679
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that report, filtered, from different forms. How do I carry the name of the current form into the
3
9408
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RecordSource of a Master Report is: Me.RecordSource = "TableOrQueryName"
4
5881
by: RLN | last post by:
RE: Access 2003 I have a SQL variable (strSQL1 dimmed as String) that gets built using Select Case logic. The first half of strSQL1 is etched in stone no matter what. The 2nd half of strSQL1 (the condition) is built depending on which option button is chosen: For option 1, I add "Condition X" to the end of strSQL1. For option 2, I add "Condition Y" to the end of strSQL1...etc.
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.