Results 1 to 6 of 6
  1. #1
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146

    vba syntax to open form from a subReport

    On frmMainMenu I have srptFollowup (subReport).
    srptFollowup has btnEditEvent.



    I want to open frmEvents on btnEditEvent Click Event to the specific record


    Code:
    Private Sub btnEditEvent_Click()
             DoCmd.OpenForm "frmEvents, acNormal,, "[EventsID] = ????? [EventsID]"
    
    End Sub

  2. #2
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    What is the control called that holds the [EventID] on the subform?

    Code:
    Private Sub btnEditEvent_Click()
             DoCmd.OpenForm "frmEvents, acNormal,, "[EventsID] = " & Me.YourControlNameGoesHere
     End Sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146
    That did it! Thanks.

    Can you describe the WHERE clause syntax?

    Code:
    Private Sub btnEditEvent_Click()
             DoCmd.OpenForm "frmEvents, acNormal,, "[EventsID] = " & Me.EventID
     End Sub

  4. #4
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Certainly - It is a string expression but you need to concatenate the value from the control(s) on your form into the string.
    So if you where to do this a little more "expanded" you could see the expression a little more clearly;


    Code:
    Private Sub btnEditEvent_Click()
        
        Dim strWhere       as String
        
        strWhere = "[EventsID] = " & Me.EventID       
        Debug.Print "Your String is : " strWhere 
    
        DoCmd.OpenForm "frmEvents, acNormal,, strWhere
    
    End Sub
    
    
    If you open the immediate window in the VBA Editor (Press Ctrl + G) you will see the result of the Debug statement.
    This is a great way of handling this type of expression as you can easily see what is being passed to the open form command.

    Debugging you code in this way can easily show up errors and what is really happening, as opposed to what you "think" is happening...
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146
    Thanks so much Minty! Another tidbit for my education.

    Learning Access and all it's workings has been very rewarding and very frustrating. Typically the rewarding comes after the frustrating

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,944
    Quote Originally Posted by mainerain View Post
    Typically the rewarding comes after the frustrating
    Made all the more sweeter though?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 7
    Last Post: 11-28-2019, 08:04 PM
  2. Replies: 4
    Last Post: 09-04-2017, 01:41 PM
  3. Replies: 7
    Last Post: 08-11-2015, 10:53 AM
  4. Syntax of rs.Open Statement
    By Philosophaie in forum Access
    Replies: 5
    Last Post: 07-05-2013, 06:24 PM
  5. Open a form based on a link in Subreport
    By RapidRepairArnold in forum Reports
    Replies: 6
    Last Post: 12-20-2012, 03:55 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