OK, let me preface this by saying that I am very, very new to VBA and realitivly new to ACCESS.
I'm trying to modify a code that will take data out of ACCESS and put it into fields in WORD. I found a code online and I'm trying to edit it to fit my purposes but I'm running into trouble.
Here is the original code:
Can someone help explain to me in as plain of language as possible what the following part of the code accomplishes?
I realize you might need more information. If so, please just let me know and I will try to answer whatever I can. I will log back on tommorrow morning (about 16 hours from now). Thanks in advance!
I'm trying to modify a code that will take data out of ACCESS and put it into fields in WORD. I found a code online and I'm trying to edit it to fit my purposes but I'm running into trouble.
Here is the original code:
Code:
Dim appWord As Word.ApplicationDim doc As Word.DocumentDim rst As ADODB.RecordsetDim strSQL As StringDim strReportsTo As StringOn Error Resume NextSet appWord = GetObject(, "Word.application")If Err = 429 Then Set appWord = New Word.Application Err = 0End IfWith appWord Set doc = .Documents(DOC_NAME) If Err = 0 Then If MsgBox("Do you want to save the current document " _ & "before updating the data?", vbYesNo) = vbYes Then .Dialogs(wdDialogFileSaveAs).Show End If doc.Close False End If On Error GoTo ErrorHandler Set doc = .Documents.Open(DOC_PATH & DOC_NAME, , True) Set rst = New ADODB.Recordset If Not IsNull(Me!ReportsTo) Then strSQL = "SELECT [FirstName] & "" "" & [LastName] AS Name FROM " _ & "Employees WHERE [EmployeeID]=" & Nz(Me!ReportsTo) rst.Open strSQL, CurrentProject.Connection, _ adOpenStatic, adLockReadOnly If Not rst.EOF Then strReportsTo = Nz(rst.Fields(0).Value) rst.Close End If End If With doc .FormFields("fldSalutation").Result = Nz(Me!TitleOfCourtesy) .FormFields("fldName").Result = Nz(Me!FirstName & " " & Me!LastName) .FormFields("fldTitle").Result = Nz(Me!Title) .FormFields("fldHireDate").Result = Nz(Me!HireDate) .FormFields("fldApprovedBy").Result = strReportsTo End With .Visible = True .ActivateEnd WithSet rst = NothingSet doc = NothingSet appWord = NothingExit SubErrorHandler:MsgBox Err & Err.Description
Can someone help explain to me in as plain of language as possible what the following part of the code accomplishes?
Code:
If Not IsNull(Me!ReportsTo) Then
strSQL = "SELECT [FirstName] & "" "" & [LastName] AS Name FROM " _
& "Employees WHERE [EmployeeID]=" & Nz(Me!ReportsTo)
rst.Open strSQL, CurrentProject.Connection, _
adOpenStatic, adLockReadOnly
If Not rst.EOF Then
strReportsTo = Nz(rst.Fields(0).Value)
rst.Close
End If
I realize you might need more information. If so, please just let me know and I will try to answer whatever I can. I will log back on tommorrow morning (about 16 hours from now). Thanks in advance!