Results 1 to 14 of 14
  1. #1
    lowesthertz is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    19

    DoCmd.OpenReport Problem


    I am having a problem getting the do.cmd.openreport to work for me. I have a form, which I have a botton on. The on_click for the button has the follow. All I am trying to do is when I have the form open, click the button to open the report with the current record in the preview screen.

    Private Sub Command382_Click()
    DoCmd.OpenReport "CAREmail", acViewPreview, , "LabNum = " & Me.LabNum
    End Sub

    So if I have the form open, with a record showing...When I click the button, the report opens but is blank (no record).

    I have a report called "CAREmail" which is basically a copy of the form. If I open the report independantly, it seems to work fine. One of my questions that might be part of the problem, the key in the table is called "LabNum", the box on the form that shows the key is "ID". Which should I be showing in the DoCmd? Any other ideas what I am doing wrong?

    Thanks
    Chris

  2. #2
    JeffChr is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    82
    try using Me!LabNum instead of Me.LabNum for the filter

  3. #3
    lowesthertz is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    19
    I get the same blank form with the "!" instead of the "."

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    One of my questions that might be part of the problem, the key in the table is called "LabNum", the box on the form that shows the key is "ID".
    You could try the following, but I'm not clear on the name of the control vs the name of the field in the table.
    DoCmd.OpenReport "CAREmail", acViewPreview, , "LabNum = " & Me.ID

    If you go to the report design view, under the data tab, perhaps you could copy and paste the
    Report's record source .

    You could post a copy of the database.

  5. #5
    lowesthertz is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    19
    Sorry if I was confusing;
    The primary key of the master table is "LabNum".
    In my form, the text box is named "ID"

    I tried the change in the doCmd and got the same result.

    When I open the report in design view, the data tab shows the control source as my "Main Data Table" that stores all the records. No filters applied on that tab.

  6. #6
    evander is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    206
    Possible Causes:


    1. The LabNum primary key is probably a text field. In this case, you should revise your argument to include single quotes.

    2. The form and report do not have the same underlying query or table data source. The report might be based on a query that uses INNER JOINS. You should check if the underlying query itself displays data. If this is the case, try to eliminate the joins first, then re-introduce your joins to see what rows are eliminated when you join two or more tables.

    3. The form is dirty, that is, the changes haven't been committed to the database yet.

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Please post some screen captures of you table design as well as your form's controls.
    I think there is confusion regarding the names of each and the data types of each.
    Primary key is not the issue here -- at least not the major issue.

  8. #8
    lowesthertz is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    19
    evander,

    1) you are correct, the key is text and an example would be "15-001". Is this what you meant with the single quotes? As written, I get the same result.

    Private Sub Command382_Click()
    DoCmd.OpenReport "CAREmail", acViewPreview, , "'LabNum' = " & Me.LabNum
    End Sub

    2) When I run the report by just double clicking on the report in the left had pane, it opens and shows records just fine. Because there are no filters, it shows all records. I just tried putting my own query in between the report and the table and I still came up with the same result. Let me ask a question, I generated the report by copy and pasting the form onto the report. Could this be causing problems? Query design shown below, very basic.

    Click image for larger version. 

Name:	query.jpg 
Views:	10 
Size:	139.6 KB 
ID:	20077

    3) it does not matter if I have made any change to the data on the form or not, I still get the same result.

  9. #9
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    If LabNum is a text data type

    try
    Private Sub Command382_Click()
    DoCmd.OpenReport "CAREmail", acViewPreview, , "LabNum = '" & Me.LabNum & "' "
    End Sub

  10. #10
    lowesthertz is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    19
    orange,
    Please see screenshots below. Is this what you were asking for?

    Click image for larger version. 

Name:	tabledesign.jpg 
Views:	10 
Size:	176.2 KB 
ID:	20078

    Click image for larger version. 

Name:	tabledesign2.jpg 
Views:	10 
Size:	180.6 KB 
ID:	20079

    Click image for larger version. 

Name:	form1.jpg 
Views:	10 
Size:	226.1 KB 
ID:	20080

  11. #11
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  12. #12
    lowesthertz is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    19
    If it is any clue at all, I also tried to generate a very basic report with only 5 or so fields from the report wizard, and I received the same result. No records showing the the report.

  13. #13
    lowesthertz is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    19
    orange, you the man! It worked! Thank you

  14. #14
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    For your own learning/training you should watch some of the videos and do the tutorials shown here.

    Good luck.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. DoCmd.OpenReport Filter Question
    By booismycat in forum Access
    Replies: 5
    Last Post: 06-12-2014, 03:32 PM
  2. DoCmd.OpenReport Where Argument
    By snipe in forum Programming
    Replies: 2
    Last Post: 04-24-2014, 10:24 AM
  3. DoCmd.OpenReport WHERE condition
    By bidbud68 in forum Programming
    Replies: 16
    Last Post: 10-19-2012, 05:31 AM
  4. Need help w/ docmd.openreport
    By jwill in forum Reports
    Replies: 3
    Last Post: 06-04-2012, 09:49 PM
  5. DoCmd OpenReport ... where condition with a Like
    By Grooz13 in forum Programming
    Replies: 4
    Last Post: 08-31-2010, 09:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums