Results 1 to 4 of 4
  1. #1
    hors34live is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2012
    Posts
    2

    Button to add a new record and to print it through a report

    Hello everybody,



    I am sure that most of you had to answer more than once to this problem, but as a newbie after spending a couple of days trying on my own to make a simple application, i have to kneel and ask for your help.

    I have a table with 2 fields a name (text) and a serial (number).
    All i want to do is to make a form to help me enter the data into my table and to print it.

    I managed to do something but i am stuck with this situation ...

    I created a button in my form to do all above (save a record and to print it through a report) with the following code :

    Private Sub Command16_Click()

    Dim strWhere As String

    If Me.Dirty Then
    Me.Dirty = False

    End If

    If Me.NewRecord Then 'Check there is a record to print
    MsgBox "bla bla"
    Else
    strWhere = "[ID] = " & Me.[ID]
    DoCmd.GoToRecord , , acNewRec
    DoCmd.OpenReport "Print_current", acViewPreview, , strWhere
    'DoCmd.RunCommand acCmdRefresh

    End If

    End Sub


    The problem that i have is that if i start this application (with a blank database), all goes as intended ... but if i exit the application and i re-enter, the forms are filled with the last record and if i am trying to make new records, this "last" record is modified with one that i enter after i re-open the application ... and so i am loosing a record each time i re-open the application.

    Please do this poor guy a favor and throw him a helping hand !

    Thank you in advance !

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can set the data entry property of the form to Yes or use the appropriate argument of OpenForm.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    It sounds as if you only want to enter New Records thru this Form; if this is correct, use Paul's first suggestion and change the Form's Data Entry Property to Yes.

    Then use this code behind your Command Button:

    Code:
    Dim strWhere As String
    
    
    If Me.Dirty Then
     
     Me.Dirty = False
    
    End If
    
    
    If Me.NewRecord Then 'If True no Record has been entered yet!
     
     MsgBox "You Must First Enter a New Record!"
    
    Else
     
     strWhere = "[ID] = " & Me.[ID]
     
     DoCmd.OpenReport "Print_current", acViewPreview, , strWhere
    
    End If


    And please, before you add this code, change your button's name to something appropriate! Names like Command16 will mean absolutely nothing to you in a month's time!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    hors34live is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2012
    Posts
    2
    Thank you folks ... to make an idea how new i am to this, i want to say that i even googled how to change the form's entry property :|
    Now it works as intended on my station but i tried to send it to a regular user to test it, and they have MS Office 2003 . I saved the application as for MS Access 2003, works fine till the report print, instead of previewing the last record, the page is blank.

    Any ideas of this issue aswell ?

    Thank you !

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

Similar Threads

  1. Replies: 7
    Last Post: 09-04-2012, 02:51 PM
  2. Replies: 1
    Last Post: 03-26-2012, 03:01 PM
  3. Replies: 8
    Last Post: 11-08-2011, 05:11 AM
  4. Replies: 0
    Last Post: 02-22-2011, 05:04 AM
  5. Error in Print Report Button
    By Robert M in forum Reports
    Replies: 16
    Last Post: 09-23-2009, 03:08 PM

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