R
ryguy7272
I keep getting a message that says the following:
Compile Error:
Method or data member not found
The code looks like this:
Private Sub CommandButton1_Click()
ListBox1.BoundColumn = 1
ActiveDocument.Variables("FirstName").Range.InsertBefore
ListBox1.ValueNext i
ListBox1.BoundColumn = 2
ActiveDocument.Variables("LastName").Range.InsertBefore
ListBox1.ValueNext i
' etc.
ActiveDocument.Fields.Update
UserForm1.Hide
End Sub
And the error occurs on this line:
ActiveDocument.Variables("FirstName").Range.InsertBefore
I got this idea form this site:
http://www.pcreview.co.uk/forums/thread-875661.php
I get my ListBox1 to load with this sub:
Sub Userform_Initialize()
Dim i As Integer, Addressee As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
' Open the database
Set db = OpenDatabase("C:\Documents and
Settings\RMS\Desktop\Contacts.xls", False, False, "Excel 8.0")
' Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `List`")
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
' Set the number of Columns = number of Fields in recordset
ListBox1.ColumnCount = rs.Fields.Count
' Load the ListBox with the retrieved records
ListBox1.Column = rs.GetRows(NoOfRecords)
'ListBox1.List = rs.GetRows(NoOfRecords) 'Transposed List
' Cleanup
rs.Close
db.Close
'AddressBlock = db
Set rs = Nothing
Set db = Nothing
End Sub
Does anyone have any ideas as to what I'm doing wrong?
This would be so awesome if I could get it to work!!!
Thanks,
Ryan--
Compile Error:
Method or data member not found
The code looks like this:
Private Sub CommandButton1_Click()
ListBox1.BoundColumn = 1
ActiveDocument.Variables("FirstName").Range.InsertBefore
ListBox1.ValueNext i
ListBox1.BoundColumn = 2
ActiveDocument.Variables("LastName").Range.InsertBefore
ListBox1.ValueNext i
' etc.
ActiveDocument.Fields.Update
UserForm1.Hide
End Sub
And the error occurs on this line:
ActiveDocument.Variables("FirstName").Range.InsertBefore
I got this idea form this site:
http://www.pcreview.co.uk/forums/thread-875661.php
I get my ListBox1 to load with this sub:
Sub Userform_Initialize()
Dim i As Integer, Addressee As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
' Open the database
Set db = OpenDatabase("C:\Documents and
Settings\RMS\Desktop\Contacts.xls", False, False, "Excel 8.0")
' Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `List`")
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
' Set the number of Columns = number of Fields in recordset
ListBox1.ColumnCount = rs.Fields.Count
' Load the ListBox with the retrieved records
ListBox1.Column = rs.GetRows(NoOfRecords)
'ListBox1.List = rs.GetRows(NoOfRecords) 'Transposed List
' Cleanup
rs.Close
db.Close
'AddressBlock = db
Set rs = Nothing
Set db = Nothing
End Sub
Does anyone have any ideas as to what I'm doing wrong?
This would be so awesome if I could get it to work!!!
Thanks,
Ryan--