Solved

Open Form and Subform based on Criteria from Dashboard

Posted on 2014-09-16
3
321 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

751 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