Results 1 to 13 of 13
  1. #1
    halo123456789 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    7

    opening a certain report based on a field in a form

    I'm new to access and I am making a simple database for the record I have for my students.



    I want to open a specific report based on the registration number [which is the autonumber] given on their form so that I can print it. I made another form for this so I can filter it. The new form is the one below.

    Click image for larger version. 

Name:	Untitled.png 
Views:	23 
Size:	246.3 KB 
ID:	39671

    I do not know what code to write so I can open the report based on the unique registration number/surname. I stopped at DoCmd.OpenReport "Form Print", acViewPreview.

    Thank you in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Use the WHERE CONDITION argument. Assuming registration number is a text field, something like:

    DoCmd.OpenReport "Form Print", acViewPreview, , "RegistrationNumber='" & Me.tbxRegistration & "'"

    Review http://allenbrowne.com/ser-62.html

    Suggest you use comboboxes instead of textboxes.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    halo123456789 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    7
    I tried but it is still not working. Whenever I enter the registration number and clicked open, It still shows the first report, not the one with the same registration number or surname.

    I already made this work before but the code was tampered and I cannot remember it anymore.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    halo123456789 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    7
    cant seem to attach the files even after following the instructions. always failed. the zip file is still too big.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Up to 2mb zip allowed. More than one file is allowed.

    Maybe can figure out what is wrong if you just post the code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    halo123456789 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    7
    It is something like this

    Private Sub open_Click()
    DoCmd.OpenReport "Form Print", acViewPreview, , "RegistrationNumber=" & Me.txbRegitrationNumber & ""
    End

    it opens the report, but now the print view and not the one with the same registration number.
    and the print command button doesnt do anything either.

  8. #8
    halo123456789 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    7
    http://www.mediafire.com/file/hjsn4w...opy.accdb/file

    idk if this works but i uploaded the db in mediafire

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    I tried that link and my computer freezes on that page. Had to reboot computer. I'm never going to that site again. I use Box.com, never had an issue with it. Many won't download files from other sites. Really need to zip and attach to forum post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    halo123456789 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    7
    new.zip new.zip i am so sorry about that. i didnt know that would happen.

    i tried to export some data into this new db.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Just took a quick look at your database and would offer the points for consideration.

    -Every table in a relational database should have a Primary Key.
    -In Access all field and object names should NOT contain embedded spaces nor special characters
    -A brief description of the purpose of your proposed database in simple, plain English helps the reader understand your requirement

    There are several articles on Database Planning and Design at the link in my signature.

    Good luck with your project.

  12. #12
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi
    As orange has mentioned there are points you need to address with this database.

    Main one being Autonumber - Primary Keys
    You have Lookup fields at table level which are NOT recommended.

    If you look at the revised database I have modified the Print / Open Command button's VB so that it now only opens the Student you have specified.

    I would recommend that you change these Unbound Textbox's to Combobox's which would allow you to search for the specific Registration Number and Student Name
    Attached Files Attached Files

  13. #13
    halo123456789 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    7
    omg. thank you so much. i'll take these into consideration.

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

Similar Threads

  1. Replies: 8
    Last Post: 08-15-2019, 02:49 PM
  2. Replies: 7
    Last Post: 12-07-2016, 01:06 AM
  3. Opening a form based on criteria
    By Jen0dorf in forum Access
    Replies: 3
    Last Post: 08-27-2016, 09:15 AM
  4. Replies: 1
    Last Post: 05-27-2013, 08:54 AM
  5. Cancel opening a form based on information
    By eww in forum Programming
    Replies: 1
    Last Post: 10-19-2010, 01:24 PM

Tags for this Thread

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