Solved

Issue opening form to specific record in VB

Posted on 2009-04-07
5
446 Views
Last Modified: 2013-11-28
I am using the code below on a button on form1 to open a new form to a specific record number. Everything seems to work but the only issue I have is when the new form opens it is "filtered" by that record number but the form actually opens to the "new record".

I would like it to open directly to that record specified, and if possible not filter it at all, only open it to the record specified.

Is this possible? Please help!
Dim stDocName, stLinkCriteria, RecordType
 
If Me.InspType = "1st Article" Then
    RecordType = "F824004 - 1st Article Inspection"
 
ElseIf Me.InspType = "Assembly" Then
    RecordType = "F824003 - Assembly Inspection"
 
ElseIf Me.InspType = "Incoming" Then
    RecordType = "F824001 - Incoming Inspection"
 
ElseIf Me.InspType = "Machining" Then
    RecordType = "F824002 - Machining Inspection"
 
ElseIf Me.InspType = "Shipping" Then
    RecordType = "F824007 - Shipping Inspection"
    
End If
 
stDocName = RecordType
 
 Me.Dirty = False
 stLinkCriteria = "[ID]=" & Me![ID]
 DoCmd.OpenForm stDocName, , , stLinkCriteria
 
 DoCmd.Close acForm, "F824005 - MRB Inspection"

Open in new window

0
Comment
Question by:filtrationproducts
[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
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:filtrationproducts
ID: 24091269
I guess the form I am trying to open has a macro assigned to the "on load" event that is pushing it to the new record. I need this to stay in place for other reasons. Is there a way I can bypass the on load event in the VB statement so it doesn't jump to a new record?
0
 
LVL 15

Expert Comment

by:MNelson831
ID: 24091326
OpenArgs:

OpenArgs Property Example

The following example uses the OpenArgs property to open the Employees form to a specific employee record and demonstrates how the OpenForm method sets the OpenArgs property. You can run this procedure as appropriate  for example, when the AfterUpdate event occurs for a custom dialog box used to enter new information about an employee.

Sub OpenToCallahan()
    DoCmd.OpenForm "Employees", acNormal, , , acReadOnly, _
     , "Callahan"
End Sub

Sub Form_Open(Cancel As Integer)
    Dim strEmployeeName As String
    ' If OpenArgs property contains employee name, find
    ' corresponding employee record and display it on form. For
    ' example,if the OpenArgs property contains "Callahan",
    ' move to first "Callahan" record.
    strEmployeeName = Forms!Employees.OpenArgs
    If Len(strEmployeeName) > 0 Then
        DoCmd.GoToControl "LastName"
        DoCmd.FindRecord strEmployeeName, , True, , True, , True
    End If
End Sub
The next example uses the FindFirst method to locate the employee named in the OpenArgs property.

Private Sub Form_Open(Cancel As Integer)
    If Not IsNull(Me.OpenArgs) Then
        Dim strEmployeeName As String
        strEmployeeName = Me.OpenArgs
        Dim RS As Recordset
        Set RS = Me.RecordsetClone
        RS.FindFirst "LastName = '" & strEmployeeName & "'"
        If Not RS.NoMatch Then
            Me.Bookmark = RS.Bookmark
        End If
    End If
End Sub
0
 
LVL 15

Accepted Solution

by:
MNelson831 earned 150 total points
ID: 24091341
You will want to alter the OnLoad Event of the second form so that IF there is no value in OpenArgs then run the macro, otherwise, just open the filtered form
0
 
LVL 1

Author Comment

by:filtrationproducts
ID: 24091656
Is this possible to do using the "DoCmd.GoToRecord" command?

I tried this but I have never used this command before so I am not sure if the syntax is correct. But if I got this to work instead it wouldn't filter the form and that would be awesome!



 stLinkCriteria = Me.ID
 DoCmd.OpenForm stDocName
 DoCmd.GoToRecord acDataForm, strLinkCriteria

Open in new window

0
 
LVL 1

Author Comment

by:filtrationproducts
ID: 24091666
Or  DoCmd.GoToRecord acDataForm, stDocName, acGoTo, stLinkCriteria
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

738 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