[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


GOTO current record based on variable name of field

Posted on 2012-09-18
Medium Priority
Last Modified: 2012-09-21
I have a form that contains an option group, When the user selects an option I would like the code to navigate to that fields on the datasheet(subform), especially if the field is currently off the screen - to the right.

Here is my current code - what is the correct declaration or code to navigate to the correct field.

Private Sub optSortChange_AfterUpdate()

Dim strWHERE As String
Dim nVar  As Variant
   On Error GoTo optSortChange_AfterUpdate_Error

    If Me.sub5.Visible = False Then Me.sub5.Visible = True
    Me.sub5.Form.Filter = ""
    Select Case optSortChange
        Case 1
            strWHERE = ""
        Case 2
            strWHERE = "Remove_Active = 'X'"
        Case 3
             strWHERE = "OrgChanged = 'X'"
             nVar = "Current_Org"
       Case 4
              strWHERE = "Bldg_Chng = 'X'"
              nVar = "Current_Bldg"
       Case 5
            strWHERE = "Location_Chg = 'X'"
            nVar = "Current_loc"
       Case 6
            strWHERE = "MS_Chg = 'X'"
            nVar = "Current_MS"
        Case 7
            strWHERE = "Active = 0"
        Case 8
            strWHERE = "Active = -1"
 End Select

    Me.sub5.Form.Filter = strWHERE
    Me.sub5.Form.FilterOn = (Len(strWHERE) > 0)
    DoCmd.GoToControl (nVar)
   On Error GoTo 0
   Exit Sub


    MsgBox "Error " & Err.Number & " (" & Err.Description & _
        ") in procedure optSortChange_AfterUpdate of VBA Document Form_frmEmpMain"

End Sub

Open in new window

My current code returns the following error msg: "There is not field named "Current_Loc" in the current record....


Question by:Karen Schaefer
LVL 29

Accepted Solution

IrogSinta earned 2000 total points
ID: 38412517
Try this in place of line 35:

Open in new window


Author Closing Comment

by:Karen Schaefer
ID: 38422685
thanks that did the trick

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.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…
Suggested Courses

834 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