Sunday, December 11, 2016

Fee Letter Save Data in Child Form

Option Compare Database
Option Explicit

Private m_ActionMode As Integer Private m_lngStoredFileInfoid As Integer Private Sub cmdCancel_Click()
DoCmd.Close acForm, Me.Name
End Sub

Private Sub cmdOK_Click()
Dim db As DAO.Database
Dim strSQL
If ValidateForm() Then
    strSQL = "INSERT INTO StoredFile (StoredFileInfoID,FileName,Description,AddedBy) VALUES " & _
        "(" & _
        m_lngStoredFileInfoid & "," & _
        "'" & Me.txtFileName.Value & "'," & _
        "'" & Me.txtDescription.Value & "'," & _
        "'" & "UT2998" & "'" & ")"
    Set db = CurrentDb()
    db.Execute strSQL, dbFailOnError
 
Else
    MsgBox "Error in saving record." & vbCrLf & _
        "Please try again", vbInformation, "Confirm Action"
    Exit Sub
End If

DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
    m_lngStoredFileInfoid = CLng(Me.OpenArgs)
Else
    Me.txtFileName.Enabled = False
End If

End Sub

Private Function ValidateForm(Optional ByVal bDisplayMessage As Boolean = True) As Boolean
Dim strMessage As String
Dim strBlankFields As String

Dim bReturn As Boolean
If IsNull(Me.txtDescription) Then
    strBlankFields = strBlankFields & "Description;"
End If

If IsNull(Me.txtFileName) Then
    strBlankFields = strBlankFields & "FileName;"
End If

If Len(strBlankFields) > 0 Then
    If bDisplayMessage Then
        MsgBox "Some required fields are blank." & vbCrLf & vbCrLf & _
            "Please fill out " & strBlankFields, vbInformation, "Confirm Action"
    End If
End If
bReturn = Len(strBlankFields) = 0
exitproc:
    ValidateForm = bReturn
End Function


=========================================================

Option Compare Database
Option Explicit

Private Sub cmdAdd_Click()
Dim strFormName As String
Dim lngPKID As Long

lngPKID = 1

strFormName = "FileDetail"
DoCmd.OpenForm strFormName, windowmode:=acDialog, OpenArgs:=lngPKID
Me.cboFeeLetterPDF.Requery
End Sub

Private Sub cmdView_Click()
Dim strFileName
Dim strMessage
Dim strPath As String
Dim lngPKID As Long

If IsNull(Me.cboFeeLetterPDF) Then
    MsgBox "Please select a file name to open"
    Exit Sub
End If
strFileName = Me.cboFeeLetterPDF.Column(1)
'If vbYes = MsgBox("Open file " & strFileName & " in Adobe", vbInformation + vbYesNo, "Confirm action") Then
    strPath = "C:\Temp"
    strFileName = strPath & "\" & strFileName
    Application.FollowHyperlink strFileName
'End If
End Sub

Private Sub Form_Load()
With Me
    .cmdDelete.Enabled = False
End With
End Sub