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!!
Thanks
Dan
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
Dan
Comment