Results 1 to 5 of 5
  1. #1
    Trojnfn is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    46

    DoCmd. Question

    I currently have a button with this command :
    DoCmd.OpenReport "Report Name", , "ID = " & Me.ID



    I have this in my search form and it will bring up all records and I click on the button and it will just display that one record that corresponds to the id, on a report. Works fine.

    What I want to do is to display that record on another form instead of a report so that I can make changes.

    I tried to use DoCmd.OpenForm and it does bring up a form but it is blank. Seems like the ID is blank or cannot be found.

    I am using the exact same code but just changed the OpenReport to OpenForm and it does not work.

    How can I do this ?

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You appear to be missing a comma.

    It really should be

    DoCmd.OpenReport "ReportName", acViewPreview, , "ID = " & Me.ID

    So, if you are just printing immediately you would either have acViewPreview set to acViewNormal or just leave it out like you have it. But you need to have THREE (3) commas after the report name for this.

    And the Form would be

    DoCmd.OpenForm "FormNameHere", acNormal, , "ID=" & Me.Id

    with the same THREE commas after the form name.

  3. #3
    Trojnfn is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    46
    Quote Originally Posted by boblarson View Post
    You appear to be missing a comma.

    It really should be

    DoCmd.OpenReport "ReportName", acViewPreview, , "ID = " & Me.ID

    So, if you are just printing immediately you would either have acViewPreview set to acViewNormal or just leave it out like you have it. But you need to have THREE (3) commas after the report name for this.

    And the Form would be

    DoCmd.OpenForm "FormNameHere", acNormal, , "ID=" & Me.Id

    with the same THREE commas after the form name.

    I made the changes but that did not seem to make any difference, so I assume it must be the form ?

    The form does display and it is completely blank. The ID that I am passing and displaying on the form (to make sure it is passing the correct value) is blank. In fact, the ID field displays (New) in it, like a table in datasheet view ready to add a new record.

    Any ideas on why the id is not being passed to get the corresponding record ?

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Make sure that the form's DATA ENTRY property isn't set to YES.

  5. #5
    Trojnfn is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    46
    Quote Originally Posted by boblarson View Post
    Make sure that the form's DATA ENTRY property isn't set to YES.
    That did it ! It was set to Yes and I changed it to No and tested and it works great, proper ID is being passed.

    Thanks for your help.

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

Similar Threads

  1. What actually happens at docmd.openform
    By Beorn in forum Programming
    Replies: 4
    Last Post: 01-05-2011, 02:19 PM
  2. my first DoCmd.RunSQL
    By broecher in forum Programming
    Replies: 4
    Last Post: 11-05-2010, 09:35 PM
  3. DoCmd.SendObject Question
    By HunterEngineeringCoop in forum Programming
    Replies: 3
    Last Post: 10-04-2010, 01:42 PM
  4. Problem with DoCmd.RunSQL
    By Peter01 in forum Programming
    Replies: 2
    Last Post: 09-10-2009, 07:11 PM
  5. DoCmd.SendObject Help
    By bgreer5050 in forum Programming
    Replies: 0
    Last Post: 01-12-2007, 06:27 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