Results 1 to 3 of 3
  1. #1
    Davince is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2015
    Posts
    6

    Macro to VBA conversion not worked - open form to record

    I 'borrowed' a bit of code from the standard Contacts template DB to try and make a combo box open a record. In the template DB it's done in Macro, so I converted it to VBA to copy over - which produced this:



    Code:
    Private Sub cboGoToContact_AfterUpdate()On Error GoTo cboGoToContact_AfterUpdate_Err
    
    
        If (IsNull(Screen.ActiveControl)) Then
            Exit Sub
        End If
        On Error Resume Next
        If (Form.Dirty) Then
            DoCmd.RunCommand acCmdSaveRecord
        End If
        If (MacroError.Number <> 0) Then
            Beep
            MsgBox MacroError.Description, vbOKOnly, ""
            Exit Sub
        End If
        On Error GoTo 0
        TempVars.Add "ActiveControlValue", "[Screen].[ActiveControl]"
        If (CurrentProject.IsTrusted) Then
            Screen.ActiveControl = Null
        End If
        If (Form.FilterOn) Then
            DoCmd.RunCommand acCmdRemoveFilterSort
        End If
        DoCmd.SearchForRecord , "", acFirst, "[ID]=" & TempVars!Activecontrolvalue
        TempVars.Remove "ActiveControlValue"
    
    
        
    
    
    
    
    cboGoToContact_AfterUpdate_Exit:
        Exit Sub
    
    
    cboGoToContact_AfterUpdate_Err:
        MsgBox Error$
        Resume cboGoToContact_AfterUpdate_Exit
    
    
    End Sub
    EDITED...

    Which doesn't work I've tried it with 3 records in the database, call them A B and C

    If you open the form on record 'A' and then choose 'B' in the combo box, it shows record 'C'. If you open record 'B' in the combo box, then choose record 'A' in the combo box, it shows Record 'C'. If you choose record 'A' or 'B' in the combo box, it shows... erm... record 'C'.

    Any ideas?

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    The combo box should be unbound, I think it is bound to ID field.
    Following line of code should find the desired record

    Code:
    Me.RecordSet.FindFirst "[ID]=" & Me.cboGoToContact

  3. #3
    Davince is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2015
    Posts
    6
    Quote Originally Posted by amrut View Post
    The combo box should be unbound, I think it is bound to ID field.
    Following line of code should find the desired record

    Code:
    Me.RecordSet.FindFirst "[ID]=" & Me.cboGoToContact

    It's unbound, it uses a select query to get a list of all contacts from a query - will see if I can get that to work with your code ta!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Macro to open table to a specific record
    By Stretholox in forum Access
    Replies: 5
    Last Post: 12-08-2014, 03:09 PM
  2. Macro to open report based on value in a form
    By iProRyan in forum Macros
    Replies: 2
    Last Post: 02-24-2014, 03:02 AM
  3. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  4. Replies: 7
    Last Post: 05-01-2012, 11:43 AM
  5. Macro to open URL from Field record
    By COiSman in forum Programming
    Replies: 3
    Last Post: 12-26-2011, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums