Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    40

    Need help wit the "DoCmd.OpenForm"


    I have a from that has a list box in it. But when I click on a line in the list nothing happens:

    The form name that has the list in it is: frmListByDate
    The list Name in that form is: Book_List
    The Form I want to go to is:
    frm_C_BookByDateAllFields
    Record Id is: C_BookID (caption is BookID)

    Here is the code I am using. (I got it from another thread in this forum but I don't remember where)

    Private Sub BOOK_LIST_Click()
    DoCmd.OpenForm "frm_C_BookByDateAllFields", , , "C_BookID = " & Me.BOOK_LIST
    End Sub

    When I click on a record in the list the line is highlighted but nothing else happens.

    Any idea what I can do to make this work?
    Any help will be greatly appreciated.
    Dave

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    The VBA code line is highlighted? Surely there is an error message?
    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
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    in addition to the error message, you also need to tell us more about your listbox - rowsource, bound column - also what datatype bookid is? text or number?

  4. #4
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    40
    I did not see an error message: or do not know how to find it. Like I said the line in the list box I clicked on is highlighted but that is all that happens.

    the rowsource is: SELECT [qry_C_ListboxByDate].C_DateLastRead, [qry_C_ListboxByDate].C_Location, [qry_C_ListboxByDate].C_BookName, [qry_C_ListboxByDate].C_BookID FROM qry_C_ListboxByDate;

    Bookid is a number

    I don't think anything is bound because the form's design view says the list box is unbound

    If you need anything else let me know

    maybe the way I'm loading the list is wrong???

  5. #5
    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
    I believe the OP means the line in the Listbox...not a line in code.

    Which column of the Listbox is the Bound Column? (Don't confuse this with the Listbox itself being Bound) C_BookID is the last Column, per your posted SQL Statement, and it would have to be the Bound Column in order for your code to work...and would not be so by default...I believe you'd have to manually change that.

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

    All posts/responses based on Access 2003/2007

  6. #6
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    40
    How do I change the C_BookID column to bound. Sorry I'm just use to access. But what you are saying makes sense.
    Dave

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Change your listbox rowsource to this:
    SELECT C_BookID, C_DateLastRead, C_Location, C_BookName FROM qry_C_ListboxByDate;
    Change the Bound Column to 1. Properties, Data tab
    Change the Column Count to 4. Properties, Format tab
    Change the Column Widths to 0;1;1;1. This will make BookID invisible and make lastread, location,and bookname all 1 inch wide in the listbox

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    There is a procedure which is presumably associated with the listbox. Something should happen, even if it is an error.
    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.

  9. #9
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    all 1 inch wide
    or one cm depending on windows settings - adjust to suit

  10. #10
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    40
    Well Thanks to you guys some progress has been made. The DoComm still does NOT work.

    BUT I created a macro (Not imbedded) and it works like a champ. the only thing I don't understand is that the macro's where command looks a lot different than I expected itto

    It says: "[C_BookID]=[Forms]![frmListByDate]![BOOK_LIST]"

    I don'tknow how to paste this into the "DoCom" to see it if this different coding will work. Ps this macro does not depend on a Bound C_BookID.

    So now I'm hopping someone can figure out how to plug the Macro's code into the DoCom command

    Things are looking better.
    Dave

  11. #11
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Have a look at this working example:


  12. #12
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    40
    davegri

    I agree that the code should work but it doesn't. I'm going to take a break and rethink what I'm doing wrong with the DoCom command .
    Sometimes I have a hard time getting access to take changes like this. Access says it does but doesn't. A rebuild will usually solve that problem.
    Thanks for the help
    Dave

  13. #13
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    in your button properties do you have '[Event Procedure]' against the click property?

    So now I'm hopping someone can figure out how to plug the Macro's code into the DoCom command
    there is an option on the ribbon to convert macros to vba code. In form design view, go to the design tab - you will see the option to the right

  14. #14
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I agree that the code should work but it doesn't.
    If you're talking about the DB that I submitted, it does work for me.
    I'm thinking maybe you downloaded my DB into a not trusted location.

  15. #15
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    40
    Ajax It was a good idea to convert the macro to vba It was turn into a function:

    Function cmdTestListClick()
    DoCmd.OpenForm "frm_C_BookByDateAllfields_B", acNormal, "", "[C_BookID]=[Forms]![frm_C_BookByDateAllfields_B]![C_BookID]", , acNormal
    End Function

    It did not work. thanks for trying.

    Davegri
    I don't know what a trusted location is I use windows explorer and win zip to unpack it.
    No go.

    Like I said I'm taking a break and have decided I can live with the macro.
    I'm hoping when I rebuild the project form the ground up it will work.
    Again thanks for the help it was all useful but at this point I'm betting on the rebuild.
    Dave

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-28-2017, 12:12 PM
  2. Replies: 7
    Last Post: 06-02-2017, 10:40 AM
  3. Replies: 3
    Last Post: 07-12-2016, 08:10 AM
  4. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  5. Replies: 3
    Last Post: 01-27-2015, 12:25 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