2014-03-19 32 views
0

我有一個訪問數據庫最初編寫於2010年(但已更新到2013年)與特定的VBA代碼來格式化一個word文檔。數據庫位於共享網絡上,我有一些用戶使用Access 2013,一些用戶使用2010.我如何使數據庫引用僅使用2010參考庫?或者讓它僅引用特定的參考庫? Microsoft Office 14對象參考庫在2010和2013都可以使用。但是,當然版本15對象參考庫不會。顯而易見的答案是升級所有人,這是慢慢完成的,但我有一些用戶正在經歷一個無法升級的傳統Citrix服務器。VBA編碼選擇特定的參考對象庫

我是VBA編碼新手,我認爲「後期綁定」代碼可以工作,但我不確定如何去創建它,哪裏是放置代碼的最佳位置。該信件必須根據我司的規格以特定格式格式化。

這也是我的第一篇文章,所以請讓我知道是否需要更詳細地解釋問題。以下是打開該字母的代碼,確保它的格式正確並具有數據庫中所需的字段。

Private Sub btnGenLetter_Click() 

'This part just makes sure required info is filled in and prompts user to fill in if not 
'If you want to use this, of course you will have to substitute the correct path and name 
'of the fields being checked. 
'If UserForm1.TextBox5.Value = "" Then 
' UserForm1.Label4.BackColor = vbRed 
' UserForm1.MultiPage1.Value = 0 
' MsgBox "Please enter Case Manager's Name." 
' Exit Sub 
' Else 
' UserForm1.Label4.BackColor = &H8000000F 
'End If 
'If UserForm1.TextBox6.Value = "" Then 
' UserForm1.Label9.BackColor = vbRed 
' UserForm1.MultiPage1.Value = 0 
' MsgBox "Please enter Case Manager's Address." 
' Exit Sub 
' Else 
' UserForm1.Label9.BackColor = &H8000000F 
'End If 
'If UserForm1.ComboBox2.Value = "" Then 
' UserForm1.Label6.BackColor = vbRed 
' UserForm1.MultiPage1.Value = 0 
' MsgBox "Please specify a Participant Support Specialist." 
' Exit Sub 
' Else 
' UserForm1.Label6.BackColor = &H8000000F 
'End If 
'If Letter1.TextBox3.Value = "" Then 
' Letter1.Label10.BackColor = vbRed 
' MsgBox "Please give the Specific Review Request." 
' Exit Sub 
' Else 
' Letter1.Label10.BackColor = &H8000000F 
'End If 
'If Letter1.TextBox4.Value = "" Then 
' Letter1.Label23.BackColor = vbRed 
' MsgBox "Please give the specific reason for denial." 
' Exit Sub 
' Else 
' Letter1.Label23.BackColor = &H8000000F 
'End If 

' Initial Letter No Follow-up 
Dim WDApp As Word.Application ' Object 
Dim WDDoc As Word.Document ' Object 
Dim Temp As String 
Dim intTab As Integer 


On Error GoTo Err_btnGenLetter_Click 

Set WDApp = CreateObject("Word.Application") 
Temp = "\\lowchen\files\DDD\Shared Directories\All Waivers Shared\Adverse Action Database\BHD Letterhead - 2011.doc" 
WDApp.Documents.Open FileName:=Temp, ReadOnly:=True 

WDApp.Visible = True 

With WDApp 
    With .Selection 
     .Font.Size = 12 
     .ParagraphFormat.Alignment = 1 
     .TypeText Text:=Format(Date, "mmmm dd, yyyy") 
     .typeParagraph 
     .typeParagraph 
     .ParagraphFormat.Alignment = wdAlignParagraphRight ' 2 
     .TypeText Text:="Ref:" & " " 
     .typeParagraph 
     .typeParagraph 
     .Font.Size = 12 
     .ParagraphFormat.Alignment = 0 
     .TypeText Text:=Forms![AdverseAction]![aa-subform-demographics]![Guardian name] & " " 
     .typeParagraph 
     .TypeText Text:=Forms![AdverseAction]![aa-subform-demographics]![guardian address] & " " 
     .typeParagraph 
     .TypeText Text:=Forms![AdverseAction]![aa-subform-demographics]![guardian city] & " " & Forms![AdverseAction]![aa-subform-demographics]![guardian state] & "," & " " & Forms![AdverseAction]![aa-subform-demographics]![guardian Zip] & " " 
'  .TypeText Text:=UserForm1.TextBox5.Value 
     .typeParagraph 
'  .TypeText Text:=UserForm1.TextBox6.Value 
     .typeParagraph 
     .typeParagraph 
     .ParagraphFormat.Alignment = wdAlignParagraphJustify ' 0 
     .ParagraphFormat.FirstLineIndent = 36 
'Examples of including a field on same subform as button (letter), and on a different subform (demographics) 
     With WDApp 
      With .Selection 
     .TypeText Text:="The team met on " _ 
       & Me![date-team-met] _ 
       & " to review the request for the participant " _ 
       & Forms![AdverseAction]![Participant Name] & ". " _ 
       & "The request was not approved, either partially or in full for the following reasons pursuant to " _ 
       & Forms![AdverseAction]![aa-subform-letter]![rule2] & ": " & " " 
     .typeParagraph 
     .typeParagraph 
       .TypeText Text:=Forms![AdverseAction]![aa-subform-letter]![actiontype2] & ". " _ 
       & Forms![AdverseAction]![aa-subform-letter]![casereview] & " " 
'& Forms![AdverseAction]![aa-subform-demographics]![Participant Name] & " " 
'TextBox4 is Guardian/Participant Address 
'    & Letter1.TextBox4.Value 
     .typeParagraph 
     .typeParagraph 
     End With 
     End With 

'CheckBox1 is "Request Denied In Full" 
     If Forms![AdverseAction]![aa-subform-letter]![fulldenial] = 1 Then 
     With WDApp 
      With .Selection 
     .TypeText Text:="The request for an IBA change was denied in full for the following reason: " _ 
      & Forms![AdverseAction]![aa-subform-letter]![denial] _ 
      & ", and therefore the IBA amount will not change." & " " 
     .typeParagraph 
     .typeParagraph 
      End With 
     End With 
     End If 
'OptionButton15 indicates Temp for the new IBA amount if true 
     If Forms![AdverseAction]![aa-subform-letter]![IBAstatus].Value = 1 Then 
     With WDApp 
      With .Selection 
     .TypeText Text:="The new temporary IBA amount will be $" _ 
     & Forms![AdverseAction]![aa-subform-letter]![NewIBA] _ 
     & " ending on " & Forms![AdverseAction]![aa-subform-letter]![tempIBAdate] & "." & " " 
     .typeParagraph 
     .typeParagraph 
      End With 
     End With 
     End If 

'OptionButton14 indicates Perm for the new IBA amount if true 
     If Forms![AdverseAction]![aa-subform-letter]![IBAstatus].Value = 2 Then 
     With WDApp 
      With .Selection 
     .TypeText Text:="The new permanent IBA amount will be $" _ 
     & Forms![AdverseAction]![aa-subform-letter]![NewIBA] & "." & " " 
     .typeParagraph 
     .typeParagraph 
      End With 
     End With 
     End If 

     .Font.Size = 10 
     .Font.Italic = True 

     .TypeText Text:="A request for reconsideration of this decision may be submitted to the Division Administrator if one of the following conditions is documented and supported in the request: 1) Information presented in the case was misrepresented; 2) Information was not represented to the fullest extent needed; 3) There was a misapplication of Division standards or policy in the case; or 4) The criteria for the case was misunderstood." 
     .typeParagraph 
     .typeParagraph 
     .TypeText Text:="Wyoming Medicaid Rules state that the participant has 30 calendar days from the date of the adverse action to request a hearing if s/he disagrees with this decision by submitting a written request for an administrative hearing to the Division Administrator. The person may have an attorney, a relative, a friend, or other spokesperson, including him or herself, represented at this hearing. The following information shall be included in the hearing request: 1) A statement of request for an administrative hearing regarding the denial; 2) The reasons why the denied request should be approved or allowed; 3) The issues to be raised at the hearing; 4) The request must be signed; and 5) The request must be typed or legibly printed." 
     .typeParagraph 
     .typeParagraph 
     .TypeText Text:="If a request for an administrative hearing concerning this action is submitted timely and appropriately, the Developmental Disabilities Division will contract with the Office of Administrative Hearings who will notify him/her of the date, time and place of the hearing and other relevant information. Rules pertaining to administrative hearing procedures are located in Wyoming Medicaid Rules, Chapter 4, Section 7." 
     .typeParagraph 
     .typeParagraph 
     .Font.Size = 12 
     .Font.Italic = False 
     .TypeText Text:="Please contact me with questions or concerns you may have in regards to this decision." 
     .typeParagraph 
     .typeParagraph 
     .ParagraphFormat.LeftIndent = 210 
     .TypeText Text:="Sincerely," 
     .typeParagraph 
     .typeParagraph 
     .typeParagraph 
     .typeParagraph 
     With WDApp 
      With .Selection 
     .TypeText Text:=Forms![AdverseAction]![aa-subform-demographics]![Participant Support Specialist] & " " 
'  .TypeText Text:=UserForm1.ComboBox2.Value 
     .typeParagraph 
     .TypeText Text:="Participant Support Specialist" 
     .typeParagraph 
     .TypeText Text:="6101 Yellowstone Road, Suite 220" 
     .typeParagraph 
     .TypeText Text:="Cheyenne, WY 82002" 

      End With 
     End With 

'Removed similar code for each PSS 
'  If UserForm1.ComboBox2.Value = "Brett Wilson" Then 
'  With WDApp 
'   With .Selection 
'  .TypeParagraph 
'  .TypeText Text:=ws.Cells(19, 1).Value 
'   End With 
'  End With 
'  End If 

     .typeParagraph 
     .typeParagraph 
     .ParagraphFormat.LeftIndent = 0 
'CheckBox23 is "Participant has Guardian" 
'TextBox3 is Guardian Name 
'TextBox4 is Guardian/Participant Address 
     If Forms![AdverseAction]![aa-subform-demographics]![guardian].Value = 1 Then 
     With WDApp 
      With .Selection 

     .TypeText Text:="C:" 
     .typeParagraph 
     .TypeText Text:=Forms![AdverseAction]![aa-subform-demographics]![CASE MANAGER] & " " 
     .typeParagraph 

      End With 
     End With 
     End If 
'  Else 

'ComboBox1 is Participant Name 
'TextBox4 is Guardian/Participant Address 
'  With WDApp 
'   With .Selection 
'  .TypeText Text:="C:" 
'  .TypeParagraph 
'  .TypeText Text:=UserForm1.ComboBox1.Value 
'  .TypeParagraph 
'  .TypeText Text:=UserForm1.TextBox4.Text 
'   End With 
'  End With 
'  End If 

End With 
    End With 

'Save today's date 
'Letter1.TextBox9.Value = Date 

    Exit Sub 
Exit_btnGenLetter_Click: 
    Exit Sub 

Err_btnGenLetter_Click: 
    MsgBox "btnGenLetter_Click: " & Err.Number & " " & Err.Description 
    Resume Exit_btnGenLetter_Click 

End Sub 

回答

0

事情是這樣的:

Dim oReference As Access.Reference 
    For Each oReference In Access.References 

     If oReference.Name Like strReferenceName Then 
      boolReferenceExists = True 
      Exit For 
     End If 

    Next 

    ' If the Reference does not exist (and it should not) 
    ' Add it to the VBA Project 
    If boolReferenceExists = False Then 
     Set oReference = References.AddFromFile(strReferenceFile) 
    End If 

哪裏strReferenceFile是你需要指出的完整路徑和文件名。