Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

Open Form and Subform based on Criteria from Dashboard

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
SparkyP
Asked:
SparkyP
  • 2
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
SparkyPAuthor Commented:
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
 
SparkyPAuthor Commented:
Scott

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

Thanks again for your help.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now