473,396 Members | 1,693 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.

Report from Form. Help with VBA Code

I wonder if anybody can help me with this problem i have. I have the code below on the click property for a command button at the bottom a form i have so that when somebody has populated the form with some data they can click the command button to preview a copy of the form as a report, then print if desired.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command85_Click()
  2.     Dim strReportName As String
  3.     Dim strCriteria As String
  4.  
  5.     If NewRecord Then
  6.         MsgBox "This record contains no data." _
  7.              , vbInformation, "Invalid Action"
  8.         Exit Sub
  9.     Else
  10.         strReportName = "rptRiskAss"
  11.         strCriteria = "[ReferenceNumber]= " & Me![ReferenceNumber]
  12.  
  13.  
  14.         DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
  15.  
  16.     End If
  17. End Sub
However when a new form is opened for data entry via a macro, the MsgBox appears as in the code above, even though data is entered in the form. How do i change the code to recognise the form with some added data as NOT a new record?
Apr 18 '07 #1
5 1298
cyberdwarf
218 Expert 100+
Hi

How are you checking for a new record?

Steve
Apr 18 '07 #2
Sorry! A bit new to this and not sure what you are asking.
The macro attached to my command button in the switchboard opens a blank form as it is set to Add in the criterea. Not sure why the form is recognised as new record if some of the txt boxes are completed before running this code.

Hi

How are you checking for a new record?

Steve
Apr 18 '07 #3
Denburt
1,356 Expert 1GB
However when a new form is opened for data entry via a macro, the MsgBox appears as in the code above, even though data is entered in the form. How do i change the code to recognise the form with some added data as NOT a new record?
Are you trying to say that when you click this button to try and retrieve the report that you see the message box?

In the beginning of your routine add the following:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdSelectRecord
  2. DoCmd.RunCommand acCmdSave
  3.  
  4.  
Apr 18 '07 #4
Thanks. It now does exactly what is says on the tin!
I know it had to be just a matter of a couple of lines of code. Easy when you know how.

Thanks
Apr 20 '07 #5
Denburt
1,356 Expert 1GB
Not a problem glad it is working for you.
Apr 20 '07 #6

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

Similar topics

4
by: deko | last post by:
I can't move a multi-page report to the last record unless I keep the popup form (that defined it's subreports) open. DoCmd.OpenReport "rptStandard", acViewNormal DoCmd.Close acForm,...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
3
by: RC | last post by:
I can't quite grasp the concept of creating custom reports depending upon what options a user picks on a Form. For example, the user clicks on a "Print Reports" button and a Form pops up. On the...
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...
6
by: Bob Alston | last post by:
I am looking for Access reporting add-in that would be easy to use by end users. My key focus is on selection criteria. I am very happy with the Access report writer capabilities. As far as...
1
by: lorirobn | last post by:
Hi, I have a report that works just fine. Now I would like to add the capability to choose selection criteria to limit what is displayed. I created several reports that do this, but they used...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
10
by: sara | last post by:
Hi - Is it possible to hide the detail section of a report at run time? I have a report that prints all details, with summary lines. The user would like the report ALSO with just summary lines....
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
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
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...
0
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...

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.