我有一个最初于2010年编写的访问数据库(但已更新至2013年),其中包含特定的VBA代码以格式化word文档。数据库位于共享网络上,我有一些用户使用Access 2013,一些用户使用2010.如何使数据库引用仅使用2010参考库?或者只引用特定的参考库? Microsoft Office 14对象引用库在2010年和2013年都可以使用。但是版本15对象引用库当然不能。显而易见的答案是升级所有人,这正在慢慢完成,但我有一些用户经历了无法升级的旧版Citrix服务器。
我是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 :(得分: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是您需要指向的完整路径和文件名。