jbarbara11
08-27-2013, 01:00 PM
Hi,
I am pulling data out of an Access db and using Word as a customized report format. I want put a Wingding character in a field on the form based on the query result. As an example of what I am trying to do, I have form with just a few fields. I have a dropdown box that gets populated from the database. I hit a Refresh button that then populates the fields. What i want is a field that updates with a wingding character, like a smiley or whatever wingding I chose. For example in the query, if the country is USA, then I put a smiley face (Wingding 74). If it is UK, then I put a star (Wingding 182). I am not sure what kind of form field to put it in, as you can see I tried a macrobutton. I cannot get this insert symbol part to work.
Here is what I have thus far:
Option Explicit'Define Variables
Private Sub UserForm_Initialize()
Dim dbDatabase As Database
Dim rsNorthwind As Recordset
Dim i As Integer
Dim aResults()
' This code activates the Database connection.
Set dbDatabase = OpenDatabase("C:\Users\jbarbara\Downloads\sharkins_hdi_dynamically_fill_Word_fields\Dynam icFormFill.mdb")
' This code opens the Employees table.
Set rsNorthwind = dbDatabase.OpenRecordset("Employees", dbOpenSnapshot)
i = 0
With rsNorthwind
' This code populates the combo box with the values
Do Until .EOF
wfLastName.AddItem (i)
wfLastName.Column(0, i) = .Fields("LastName")
.MoveNext
i = i + 1
Loop
End With
End Sub
Sub FillDependentFields()
'Fill form fields based on selected employee
'in wfEmployeeDropdown.
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim doc As Document
Dim strSQL As String
Dim strPath As String
Dim f As Field
Set doc = ThisDocument
strSQL = "SELECT TitleOfCourtesy, FirstName, Country FROM Employees " _
& "WHERE LastName = '" _
& wfLastName.Value _
& "'"
strPath = "C:\Users\jbarbara\Downloads\sharkins_hdi_dynamically_fill_Word_fields\Dynam icFormFill.mdb"
Set db = OpenDatabase(strPath)
Set rst = db.OpenRecordset(strSQL)
'Ignore Null values from Access data.
On Error Resume Next
wfTitleOfCourtesy.Text = rst(0).Value
wfFirstName.Text = rst(1).Value
doc.FormFields("wfCountry").Result = rst(2).Value
f.Code.Font.Name = "WingDings"
If rst(2).Value = "USA" Then
f.Code.Text = "MACROBUTTON " + Chr(74)
End If
If rst(2).Value = "UK" Then
f.Code.Text = "MACROBUTTON " + Chr(182)
End If
'If rst(2).Value = "USA" Then doc.FormFields("Check1").CheckBox.Value = True
'If rst(2).Value <> "USA" Then doc.FormFields("Check1").CheckBox.Value = False
'doc.FormFields("wfTitleOfCourtesy").Result = rst(0).Value
Set db = Nothing
Set rst = Nothing
End Sub
Private Sub CommandButton1_Click()
FillDependentFields
End Sub
Private Sub Document_Close()
'Clear fields.
Dim doc As Document
Set doc = ThisDocument
doc.FormFields("wfFirstName").TextInput.Clear
doc.FormFields("wfTitleOfCourtesy").TextInput.Clear
'Close without saving or prompting.
ActiveDocument.Saved = True
End Sub
Private Sub wfLastName_Click()
End Sub
Private Sub wfTitleOfCourtesy_Click()
End Sub
Private Sub wfTitleOfCourtesy_Change()
End Sub
Looking forward to some help...Thanks in Advance!
I am pulling data out of an Access db and using Word as a customized report format. I want put a Wingding character in a field on the form based on the query result. As an example of what I am trying to do, I have form with just a few fields. I have a dropdown box that gets populated from the database. I hit a Refresh button that then populates the fields. What i want is a field that updates with a wingding character, like a smiley or whatever wingding I chose. For example in the query, if the country is USA, then I put a smiley face (Wingding 74). If it is UK, then I put a star (Wingding 182). I am not sure what kind of form field to put it in, as you can see I tried a macrobutton. I cannot get this insert symbol part to work.
Here is what I have thus far:
Option Explicit'Define Variables
Private Sub UserForm_Initialize()
Dim dbDatabase As Database
Dim rsNorthwind As Recordset
Dim i As Integer
Dim aResults()
' This code activates the Database connection.
Set dbDatabase = OpenDatabase("C:\Users\jbarbara\Downloads\sharkins_hdi_dynamically_fill_Word_fields\Dynam icFormFill.mdb")
' This code opens the Employees table.
Set rsNorthwind = dbDatabase.OpenRecordset("Employees", dbOpenSnapshot)
i = 0
With rsNorthwind
' This code populates the combo box with the values
Do Until .EOF
wfLastName.AddItem (i)
wfLastName.Column(0, i) = .Fields("LastName")
.MoveNext
i = i + 1
Loop
End With
End Sub
Sub FillDependentFields()
'Fill form fields based on selected employee
'in wfEmployeeDropdown.
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim doc As Document
Dim strSQL As String
Dim strPath As String
Dim f As Field
Set doc = ThisDocument
strSQL = "SELECT TitleOfCourtesy, FirstName, Country FROM Employees " _
& "WHERE LastName = '" _
& wfLastName.Value _
& "'"
strPath = "C:\Users\jbarbara\Downloads\sharkins_hdi_dynamically_fill_Word_fields\Dynam icFormFill.mdb"
Set db = OpenDatabase(strPath)
Set rst = db.OpenRecordset(strSQL)
'Ignore Null values from Access data.
On Error Resume Next
wfTitleOfCourtesy.Text = rst(0).Value
wfFirstName.Text = rst(1).Value
doc.FormFields("wfCountry").Result = rst(2).Value
f.Code.Font.Name = "WingDings"
If rst(2).Value = "USA" Then
f.Code.Text = "MACROBUTTON " + Chr(74)
End If
If rst(2).Value = "UK" Then
f.Code.Text = "MACROBUTTON " + Chr(182)
End If
'If rst(2).Value = "USA" Then doc.FormFields("Check1").CheckBox.Value = True
'If rst(2).Value <> "USA" Then doc.FormFields("Check1").CheckBox.Value = False
'doc.FormFields("wfTitleOfCourtesy").Result = rst(0).Value
Set db = Nothing
Set rst = Nothing
End Sub
Private Sub CommandButton1_Click()
FillDependentFields
End Sub
Private Sub Document_Close()
'Clear fields.
Dim doc As Document
Set doc = ThisDocument
doc.FormFields("wfFirstName").TextInput.Clear
doc.FormFields("wfTitleOfCourtesy").TextInput.Clear
'Close without saving or prompting.
ActiveDocument.Saved = True
End Sub
Private Sub wfLastName_Click()
End Sub
Private Sub wfTitleOfCourtesy_Click()
End Sub
Private Sub wfTitleOfCourtesy_Change()
End Sub
Looking forward to some help...Thanks in Advance!