473,385 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Limit cmdOpenReport to single record set from a form

Any help would be appreciated. I have a simple form (frmSoapPelletCoA) with a 'Report' button that I would like to print preview a single record set into a report (rptSoapPelletCoA) based on the 'Material IDH'(text field). It should go through a query named qryCoAHistory. The following code results in an Enter Parameter Value: Material_IDH pop up. I would like it to automatically go through to the report.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdReportPrintPreview_Click()
  2. On Error GoTo Err_cmdReportPrintPreview_Click
  3.  
  4.     Dim strDocName As String
  5.     Dim strWhere As String
  6.     strDocName = "rptSoapPelletCoA"
  7.     strWhere = "Material_IDH='" & Me.Material_IDH.Value & "'"
  8.     DoCmd.OpenReport strDocName, acPreview, , strWhere
  9.  
  10.  
  11. Exit_cmdReportPrintPreview_Click:
  12.     Exit Sub
  13.  
  14. Err_cmdReportPrintPreview_Click:
  15.     MsgBox Err.Description
  16.     Resume Exit_cmdReportPrintPreview_Click
  17.  
  18. End Sub
Nov 26 '13 #1
5 1389
zmbd
5,501 Expert Mod 4TB
You do not state what, if anything, you are getting now.

Please look at line 7
strWhere = "Material_IDH='" & Me.Material_IDH.Value & "'"

Unless Me.Material_IDH.Value is a string/text then you can and should remove the single quotes
strWhere = "Material_IDH=" & Me.Material_IDH.Value

Also you have a "Material_IDH pop up" you need to go back to the table/query that the report is based on and do two things:

1) Check that the field is actually there (you'd be amazed howmany times in a query the field was omitted by accident!)
I don't suspect this is the issue; however, easy enough to double check.
2) Check that "Material_IDH" is actually spelled that way...usually, now days, case doesn't matter; however, I try to match the case anyway (old school habits are hard to break).

Insert between line7 and line8
debug.print "strWhere = " & strWhere
run your code press <ctrl><g> the immediates window in the VBE will open, please take note of the resulting string. and post it back here.

If the Report is based on a query, please open the query in design view, right click on an empty space in the tables area, selct SQL view from the popup.

Paste that text into a post in this thread, select the pasted text in the post and click on the [CODE/] formatting button in the toolbar.
Nov 26 '13 #2
Material_IDH is a text field.

Yes, Material IDH is there and spelled correctly.

<ctrl><g> came up with nothing in the Immediate window.

The report is based on a query. See below:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblCoAHistory.[Material IDH]
  2.    , tblSoapPelletSpecs.Description
  3.    , tblCoAHistory.[Production Date]
  4.    , tblCoAHistory.[Batch Code]
  5.    , tblCoAHistory.[NaCl,%]
  6.    , tblCoAHistory.[Glycerin,%]
  7.    , tblCoAHistory.[Sorbitol,%]
  8.    , tblCoAHistory.[Alkalinity,%]
  9.    , tblCoAHistory.[Free Fatty Acid,%]
  10.    , tblCoAHistory.[Moisture,%]
  11.    , tblCoAHistory.Color
  12.    , tblCoAHistory.Odor
  13.    , tblCoAHistory.[Foreign Matter]
  14. FROM tblSoapPelletSpecs 
  15.    INNER JOIN tblCoAHistory 
  16.       ON tblSoapPelletSpecs.[Material IDH] 
  17.          = tblCoAHistory.[Material IDH];
Nov 26 '13 #3
zmbd
5,501 Expert Mod 4TB
Material_IDH is a text field.
Sigh, was hoping for the simple fix :)

Yes, Material IDH is there and spelled correctly.
As I thought; however, it is such a common issue that it's always worth a double check.

<ctrl><g> came up with nothing in the Immediate window.
(?_?)
You did place:
debug.print "strWhere = " & strWhere
between lines 7 and 8 first?
You should have at least seen "strWhere = "

SQL:
"SELECT tblCoAHistory.[Material IDH], "

You have an underscore in Line7 of the code block in post#1
You do not have an underscore here... this would be a typo and why you are getting the prompt.
Change line7 to:"Material IDH='" & Me.Material_IDH.Value & "'"
Let us know what happens.

As I mentioned, the typo is one of the most common issues.
Please double check all of your field references in the code vs. the field names in the SQL.

BTW: Although is now allowed in code and SQL for many of the newer versions of software, it is still advisable to use the underscore and not spaces in field names and in general to not use anything except alphanumerics:
Access 2007 reserved words and symbols
AllenBrowne- Problem names and reserved words in Access
Using that comma and the percent sign in the field names will come back and haunt you... in the very near future!
Nov 26 '13 #4
dgunner71
110 100+
Pookaro85,

You might also try to specify the column.

If your combobox has a different bound column than the value you're trying to run the report on, you may have trouble. It might be safer to use:

Expand|Select|Wrap|Line Numbers
  1. strWhere = "Material_IDH='" & Me.Material_IDH.Column(1) & "'"
Where column 1 is the actual value you want to use for the displayed value.

Gunner
Nov 30 '13 #5
zmbd
5,501 Expert Mod 4TB
The solution offered by dgunner71 is not needed:

There is no need to refer to the specfic column IF the control has the bound column property set then the value of the control is the value of the bound columm. Doing this adds an additional level of complication that is unneeded.

Furthermore, this reference will not fix the issue as the field is still mis-spelled.
-z
Nov 30 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Andy | last post by:
Hi All. I'm working for a company that has set out a guideline for retrieving data from a database. Nobody can explain to me the reason for the following. When retrieving a set of records...
22
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is Access 2000 with the latest service pack of JET 4....
6
by: ApexData | last post by:
When I use Dlookup. I am only able to return a single value and therefore cannot seem to assign a single records (3-field values) to (3-Variables). I noticed that I can get the 3-field values, but...
6
by: Aussie Rules | last post by:
Hi, In all my coding to date, i have been dealing with multiple results in my dataset, looping through them with SqlDataAdapterContactProfile.Fill(contact, "Profile") For Each pRow In...
2
by: jamieda | last post by:
I have a multiple items form displaying the contents of a table. It has a primary key and the records are ordered by this. I want to be able to manually select a record in the form and then...
0
by: AmateurDBer | last post by:
Hello, I'm looking for Allen. I hate to bother you again, but I am now trying to e-mail the single record from the same form mentioned before (using a macro button) (reference thread about...
2
by: Greg (codepug | last post by:
acCmdPrint allows me to print using the Windows Dialog. Since I want to be able to select the printer of my choice, this works well. I put his behind a button on a single form. The problem is,...
1
Jerry Maiapu
by: Jerry Maiapu | last post by:
Hi Please help. How can I delete i single record in a datsheet subform from main form using a delete button on the parent form.? i will be more grateful for your help... jm
2
by: simulationguy | last post by:
I have a report that prints all of the records out from a table, usually executed from a reports menu. The user also wants a print button on the data entry form that will print out the exact same...
8
by: eltigreferoz | last post by:
Hello. I've been trying to create a button on my ACCESS 2007 form that will send a pdf via email of a single record. At the moment (and using code from a previous forum) I have been successful in...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.