473,396 Members | 1,755 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,396 software developers and data experts.

Need to make a report from a value on Form

Problem:

Have a data entry form that enters new records that we need to print
invoices from when the form is completed.

I expect to be able to place a command button on the form and print the
invoice, but just can't seem to understand the correct way to pass the value
to the report and return to a new form.

The form uses tblInvoice as the data source, it has a primary key ID1
(autonumber). I think we should be able to use ID1 selection to print just
this record to rptInvoice1 (a report for a custom multi-part invoice), then
it should go back to the new invoice form.

Any suggestions? Perhaps someone knows of a good reference that shows the
way access handles data so that I can learn the proper way to pass values?


Nov 12 '05 #1
4 1753
Your command button needs something like this in its Click event procedure:

Private Sub cmdPrint_Click()
If Me.Dirty Then 'Save any changes.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print.
MsgBox "Select a record to print."
Else
DoCmd.OpenReport "rptInvoice", acViewPreview, , "[ID1] = " &
Me.[ID1]
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"JC Mugs" <jc****@hotmail.com> wrote in message
news:vv************@corp.supernews.com...
Problem:

Have a data entry form that enters new records that we need to print
invoices from when the form is completed.

I expect to be able to place a command button on the form and print the
invoice, but just can't seem to understand the correct way to pass the value to the report and return to a new form.

The form uses tblInvoice as the data source, it has a primary key ID1
(autonumber). I think we should be able to use ID1 selection to print just
this record to rptInvoice1 (a report for a custom multi-part invoice), then it should go back to the new invoice form.

Any suggestions? Perhaps someone knows of a good reference that shows the
way access handles data so that I can learn the proper way to pass

values?
Nov 12 '05 #2
Dim g_WHERE as string

g_WHERE = " [ID1] = " & txtBOX
docmd.openreport "reportname",acviewnormal,,g_where
exit function

the above will print the report, listing only the matching records and leave
the invoice form open for further use

John Bickmore
www.BicycleCam.com
www.Feed-Zone.com

"JC Mugs" <jc****@hotmail.com> wrote in message
news:vv************@corp.supernews.com...
Problem:

Have a data entry form that enters new records that we need to print
invoices from when the form is completed.

I expect to be able to place a command button on the form and print the
invoice, but just can't seem to understand the correct way to pass the value to the report and return to a new form.

The form uses tblInvoice as the data source, it has a primary key ID1
(autonumber). I think we should be able to use ID1 selection to print just
this record to rptInvoice1 (a report for a custom multi-part invoice), then it should go back to the new invoice form.

Any suggestions? Perhaps someone knows of a good reference that shows the
way access handles data so that I can learn the proper way to pass values?

Nov 12 '05 #3
JC,

One way to handle this would be to to construct a recordset in the
"Report_Open" event that reads the value on the form. You can store
this value in a global variable or preferably, a class. A sample of
some code doing this is below:

Private Sub Report_Open(Cancel As Integer)

Dim strSQL As String

strSQL = "SELECT [Employee_ID], " & _
"[Fiscal_Year], " & _
"[FY_End_Date], " & _
"[SumOfEnding_Balance] AS Ending_Balance_Net " & _
"FROM qryselCumulativeSummary " & _
"WHERE [Fiscal_Year] <= " & CStr(cGenSpecs.CurrentFY) &
";"

Me.RecordSource = strSQL

End Sub

"CGenSpecs.CurrentFY" stores the current fiscal year, and the query
gets salaries for a given fiscal year. You need to already have
defined a recordsource for the report, and it helps to have bound the
controls on the report - you can bind them at runtime, but the code
can get messy.

Another altearnative is to assign a filter to the report, in the same
area - perhaps something like this:

Private Sub Report_Open(Cancel As Integer)

Dim strEmpID As String

Me.Filter = "Employee_ID = " & g_strEmpID
Me.FilterOn = True

End Sub

"g_strEmpID" is (gasp!) a global variable, and yes, I was being lazy
by not creating a class.

You can assign some code to the form, perhaps on a command button, to
instantiate the report, either to print it out, or view it. Code
might appear as such, just be advised this has no vaildation or
anything like that:

Sub WTF

DoCmd.OpenReport "rptStatement", acViewNormal

End Sub
HTH,

JCN
"JC Mugs" <jc****@hotmail.com> wrote in message news:<vv************@corp.supernews.com>...
Problem:

Have a data entry form that enters new records that we need to print
invoices from when the form is completed.

I expect to be able to place a command button on the form and print the
invoice, but just can't seem to understand the correct way to pass the value
to the report and return to a new form.

The form uses tblInvoice as the data source, it has a primary key ID1
(autonumber). I think we should be able to use ID1 selection to print just
this record to rptInvoice1 (a report for a custom multi-part invoice), then
it should go back to the new invoice form.

Any suggestions? Perhaps someone knows of a good reference that shows the
way access handles data so that I can learn the proper way to pass values?

Nov 12 '05 #4
"JC Mugs" <jc****@hotmail.com> wrote in message news:<vv************@corp.supernews.com>...
Problem:

Have a data entry form that enters new records that we need to print
invoices from when the form is completed.

I expect to be able to place a command button on the form and print the
invoice, but just can't seem to understand the correct way to pass the value
to the report and return to a new form.

The form uses tblInvoice as the data source, it has a primary key ID1
(autonumber). I think we should be able to use ID1 selection to print just
this record to rptInvoice1 (a report for a custom multi-part invoice), then
it should go back to the new invoice form.

Any suggestions? Perhaps someone knows of a good reference that shows the
way access handles data so that I can learn the proper way to pass values?


Create the report as usual (unfiltered). then pass the filter you
want from your form in the Open event of the report. something like

dim strFilter as string
strFilter = "[MyField]=Me![Some Field]
DoCmd.OpenReport "rptMyReport",,,strFilter

If your VB editor is working right, you should be "prompted" for the
proper syntax. If you're having a problem, you can create a macro
that opens your report and then convert it to VB.
Nov 12 '05 #5

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

Similar topics

2
by: Axel Foley | last post by:
Hi Folks, i'm newbie at JS; but "learning by tweaking" is my middle name! Trying to set up a link partnership application on a client's site; got this script at "The Javascript Source", but it...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
1
by: Regnab | last post by:
The record's primary key is the report number. The form in which data is entered or modified has this Report Number at the top. I would like to know if I could use SQL in the VB code so that on...
0
by: Rahul Chatterjee | last post by:
Hello All I have designed a dotnet application using VB which basically takes a selection and passes value to a crystal report which in turn passes the value to a Stored procedure. After the...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
0
by: Phils | last post by:
Hello guys; I i have just found the solution to my problem but would like to full understand the solution so would be great full if you could enlighten me. OUR Set-up
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.