Solved

Open Form and Subform based on Criteria from Dashboard

Posted on 2014-09-16
3
320 Views
Last Modified: 2014-09-16
I have a Dashboard with a datasheet listing Audit questions. I have a On Click Event on the records to open up a Form based on detail in a login Form (this form is hidden on opening the dashboard).

The following code works fine for opening the Main form on the specific Record


Dim strWhere As String

strWhere = "[StdID]=" & Forms!frmdatabaselogin![cboStandard]
DoCmd.OpenForm "mjpAuditorsAnswerMaster", , , strWhere

What II want the subform to go to the specific question from the dashboard, something like Me!questionID = forms!mainForm!Subform!QuesionID



Can this be done, and if so, what code and order is needed.
0
Comment
Question by:SparkyP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40325070
You'd have to do this in the OpenArgs of your MainForm, I'd think. The Subform is opened and populated prior to your MainForm, so perhaps something like this:

Sub Form_Open()
If Nz(Me.OpenArgs, "") <> "" Then
  Dim QuestionID as Integer
  QuestionID = CInt(Me.OpenArgs)
  Dim rst As DAO.Recordset
  Set rst = Me.NameOfYourSubformCONTROL.Form.Recordset
  rst.FindFirst "QuestionID=" & QuestionID
  If Not rst.NoMatch Then
    Me.NameOfYourSubformCONTROL.Form.Bookmark = rst.Bookmark
  End If
End If

End Sub

Open in new window

This assumes that QuestionID is a Numeric value. If not, you'll have to make changes.

Note that NameOfYourSubformCONTROL is the name of the Subform Control on your main form. It may or may not be the same as the form you're using as the Subform

Subform Control
0
 

Author Comment

by:SparkyP
ID: 40325131
Scott

Please bear with me, OpenArgs is completely new to me.

Do I leave my original code on the click event of the Dashboard, which opens the correct Main Form record.

Where do I put the OpenArgs code?
How is it referring to the QstnID on the record in the dashboard

If Nz(Me.OpenArgs, "") <> "" Then
  Dim QuestionID as Integer
  QuestionID = CInt(Me.OpenArgs)
  Dim rst As DAO.Recordset
  Set rst = Me.mjpAuditorsAnswers.Form.Recordset
  rst.FindFirst "QuestionID=" & QuestionID
  If Not rst.NoMatch Then
    Me.mjpAuditorsAnswers.Form.Bookmark = rst.Bookmark
  End If
End If

Thank you
0
 

Author Closing Comment

by:SparkyP
ID: 40325514
Scott

Has been a steep learning curve this afternoon, but got there.

Thanks again for your help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question