What is wrong with this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DAHMB
    New Member
    • Nov 2007
    • 147

    What is wrong with this?

    I am trying to launch a form and fgo to a specific record with the on click event. The key control is the MemoID and the form I want to launch is called frmMemo. Here is my code but it won't work. I get an erro saying that the form is not connected to a table, but it is!!

    Code:
    Private Sub To_Click()
    On Error GoTo To_Click_Err
    
        On Error Resume Next
        If ([frmMemo].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
        DoCmd.OpenForm "frmMemo", acNormal, "", "[MemoID]=" & Nz(MemoID, 0), , acDialog
        If (Not IsNull(MemoID)) Then
            TempVars.Add "CurrentID", "[MemoID]"
        End If
        If (IsNull(MemoID)) Then
            TempVars.Add "CurrentID", "Nz(DMax(""[MemoID]"",[frmMemo].[RecordSource]),0)"
        End If
        DoCmd.Requery ""
        DoCmd.SearchForRecord , "", acFirst, "[Table]![tblMemos]![MemoID]=" & TempVars!CurrentID
        TempVars.Remove "CurrentID"
    
    
    To_Click_Exit:
        Exit Sub
    
    To_Click_Err:
        MsgBox Error$
        Resume To_Click_Exit
    
    End Sub
    Thanks
    Dan
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Originally posted by DAHMB
    I am trying to launch a form and fgo to a specific record with the on click event. The key control is the MemoID and the form I want to launch is called frmMemo. Here is my code but it won't work. I get an erro saying that the form is not connected to a table, but it is!!

    Code:
    ...
    On Error GoTo To_Click_Err
     
    On Error Resume Next
    ...
    On Error GoTo 0
    ...
    DoCmd.SearchForRecord , "", acFirst, "[Table]![tblMemos]![MemoID]=" & TempVars!CurrentID
    TempVars.Remove "CurrentID"
    ...
    To_Click_Exit:
    Exit Sub
     
    To_Click_Err:
    MsgBox Error$
    Resume To_Click_Exit
     
    End Sub
    Thanks
    Dan
    Hi. Although I do not use Access 2007 (the version you must be using, although you haven't said) the clause in the DoCmd.SearchFor Records is incorrect. You are trying to specify a field name in the way you would a fully qualified form field name, and unless Access 2007 has changed the way it is done you just refer to the field name itself, as in an SQL WHERE clause. Try changing this line to
    [code=vb]DoCmd.SearchFor Record , "", acFirst, "[MemoID] = " & TempVars!Curren tID[/code]

    There is a help entry for the SearchForRecord method on MSDN at http://msdn2.microsoft.com/en-us/library/bb238954.aspx

    By the way, there are three On Error statements in your code, the first of which is immediately overtaken by the second, and the third of which is a Goto 0 with no corresponding line number listed to branch to.

    -Stewart

    Comment

    • DAHMB
      New Member
      • Nov 2007
      • 147

      #3
      Originally posted by Stewart Ross Inverness
      Hi. Although I do not use Access 2007 (the version you must be using, although you haven't said) the clause in the DoCmd.SearchFor Records is incorrect. You are trying to specify a field name in the way you would a fully qualified form field name, and unless Access 2007 has changed the way it is done you just refer to the field name itself, as in an SQL WHERE clause. Try changing this line to
      [code=vb]DoCmd.SearchFor Record , "", acFirst, "[MemoID] = " & TempVars!Curren tID[/code]

      There is a help entry for the SearchForRecord method on MSDN at http://msdn2.microsoft.com/en-us/library/bb238954.aspx

      By the way, there are three On Error statements in your code, the first of which is immediately overtaken by the second, and the third of which is a Goto 0 with no corresponding line number listed to branch to.

      -Stewart

      Thank you very much, that was my problem and I have fixed my OnError issue too thank you.
      Dan

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Something else confuses me about your code. You state that from the OnClick event "the form I want to launch is called frmMemo" and yet in Line #5 of your code, before you've opened frmMemo, you're trying to check to see if it's Dirty!

        Code:
         Private Sub To_Click()
         On Error GoTo To_Click_Err
         
             On Error Resume Next
             If ([frmMemo].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
             DoCmd.OpenForm "frmMemo", acNormal, "", "[MemoID]=" & Nz(MemoID, 0), , acDialog
             If (Not IsNull(MemoID)) Then
                 TempVars.Add "CurrentID", "[MemoID]"
             End If
             If (IsNull(MemoID)) Then
                 TempVars.Add "CurrentID", "Nz(DMax(""[MemoID]"",[frmMemo].[RecordSource]),0)"
             End If
             DoCmd.Requery ""
             DoCmd.SearchForRecord , "", acFirst, "[Table]![tblMemos]![MemoID]=" & TempVars!CurrentID
             TempVars.Remove "CurrentID"
         
         
         To_Click_Exit:
             Exit Sub
         
         To_Click_Err:
             MsgBox Error$
             Resume To_Click_Exit
         
         End Sub
        Linq ;0)>

        Comment

        Working...