Results 1 to 6 of 6
  1. #1
    Molly152 is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    5

    OnClick open

    Hello

    On my form I have a list box called lstChristmasCard, when on click I want to open frmFRONTSHEET where CnBio_ID = CnBio_ID. The code I have, which does not work, is below. Please can someone tell me what I am doing wrong and help me make this work. Thank you.



    Dim StDocName As String
    Dim StLinkCriteria As String
    St DocName = "frmFRONTSHEET"
    DoCmd.OpenForm , , StDocName, , , StLinkCriteria
    StLinkCriteria = "[CnBio_ID]=" & Me![CnBio_ID]

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,035
    Hi,

    on the moment you open the form the string stLinkCriteria is still empty. Try :

    Dim StDocName As String
    Dim StLinkCriteria As String

    St DocName = "frmFRONTSHEET"
    StLinkCriteria = "[CnBio_ID]=" & Me![CnBio_ID]
    DoCmd.OpenForm , , StDocName, , , StLinkCriteria

  3. #3
    Molly152 is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    5
    Hi

    Thanks for response. I have changed the code as below but still when I click on the name in the list box nothing happens, do I have to reference the list box at all?


    St DocName = "frmFRONTSHEET"
    StLinkCriter = [CnBio_ID] = "&Me![CnBio_ID]"
    DoCmd.OpenForm , , stDocName, , , stLinkCriteria

  4. #4
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,035
    Hi,

    If you want something to happen when you click on something, you have to enter the code in the OnClick event of that object.

    gr
    NG

  5. #5
    Molly152 is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    5
    Yes, on the property sheet, under event, "On Click" [Event procedure] has been selected, but nothing happens!

    Private Sub LstChristmasCard_Click()

    Dim StDocName As String
    Dim StLinkCriteria As String
    St DocName = "frmFRONTSHEET"
    DoCmd.OpenForm , , StDocName, , , StLinkCriteria
    StLinkCriteria = "[CnBio_ID]=" & Me![CnBio_ID]
    End Sub

  6. #6
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,035
    Hi,

    do you have the option explicit turned on? If the code was a copy paste then there is a spelling mistake in the name of the variable: St DocName in stead of StDocname, so the variable stDocname never gets filled, Access just creates a new variable on the fly. To avoid this, type "Option explicit" on top of the module, so you'll be warned of typo's.

    Try the code:

    Private Sub LstChristmasCard_Click()

    Dim StDocName As String
    Dim StLinkCriteria As String

    StDocName = "frmFRONTSHEET"
    StLinkCriteria = "[CnBio_ID] = " & Me![CnBio_ID]
    DoCmd.OpenForm , , StDocName, , , StLinkCriteria

    end Sub

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

Similar Threads

  1. OLEunbound onclick event
    By thangasiva in forum Forms
    Replies: 1
    Last Post: 03-26-2015, 10:55 AM
  2. Onclick event
    By tmcrouse in forum Forms
    Replies: 3
    Last Post: 09-18-2010, 01:10 PM
  3. OLEunbound onclick event
    By thangasiva in forum Access
    Replies: 1
    Last Post: 06-27-2010, 01:49 PM
  4. Set onclick via VBA
    By Gerry in forum Programming
    Replies: 6
    Last Post: 04-19-2010, 09:23 AM
  5. OnClick event
    By HotTomales in forum Forms
    Replies: 1
    Last Post: 12-24-2009, 08:10 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