F
Frenk Nijssen
Hi,
I have code accessing a named range in an excel sheet, filling a formfield
in word,
the access and display is in a vba created form list of values, where the
user can select the value he/she wants. The display is ok, the form displays
all selected(378 records) values, but when a selected value greater then the
row 200 the value is not filled out in the formfield, everyting below this is
ok..
Do i have to change my code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
' If no databasefile has been found reinit it.
If dataDs_Filename = "" Then
dataDs_Filename = "\\myExcelbook.xls"
End If
' Fetch tabbed out formfield, this will determine the fieldname of where
the
' data from the LoV will be put in.
If Selection.FormFields.Count = 1 Then
' No textbox but a check- or listbox
MyFieldStr = Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0
Then
MyFieldStr = Selection.Bookmarks(Selection.Bookmarks.Count).Name
End If
' Init the global field MyField for Lov
Set MyField = ActiveDocument.FormFields(MyFieldStr)
' Open the database an Excel file see dataDs_Filename
Set db = OpenDatabase(dataDs_Filename, False, False, "Excel 8.0")
' display countries
If MyFieldStr = "countries_man" Then
Set rs = db.OpenRecordset("SELECT * FROM `countries`")
' display departments
ElseIf MyFieldStr = "departments_man" Then
Set rs = db.OpenRecordset("SELECT * FROM `departments`")
Else
' No RecordSet has been found and therefor no LoV should be displayed.
db.Close
Set db = Nothing
GoTo NoLoV
End If
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
' Set the number of Columns = number of Fields in recordset
LovForm.ListBox1.ColumnCount = rs.Fields.Count
' Load the ListBox with the retrieved records
LovForm.ListBox1.Column = rs.GetRows(NoOfRecords)
' Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
' display the list of values form
LovForm.Show
'DEBUG MsgBox ("ShowLov " & MyFieldStr)
' Tag to abort procedure and do nothing.
NoLoV:
End Sub
Thanks in advance.
I have code accessing a named range in an excel sheet, filling a formfield
in word,
the access and display is in a vba created form list of values, where the
user can select the value he/she wants. The display is ok, the form displays
all selected(378 records) values, but when a selected value greater then the
row 200 the value is not filled out in the formfield, everyting below this is
ok..
Do i have to change my code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
' If no databasefile has been found reinit it.
If dataDs_Filename = "" Then
dataDs_Filename = "\\myExcelbook.xls"
End If
' Fetch tabbed out formfield, this will determine the fieldname of where
the
' data from the LoV will be put in.
If Selection.FormFields.Count = 1 Then
' No textbox but a check- or listbox
MyFieldStr = Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0
Then
MyFieldStr = Selection.Bookmarks(Selection.Bookmarks.Count).Name
End If
' Init the global field MyField for Lov
Set MyField = ActiveDocument.FormFields(MyFieldStr)
' Open the database an Excel file see dataDs_Filename
Set db = OpenDatabase(dataDs_Filename, False, False, "Excel 8.0")
' display countries
If MyFieldStr = "countries_man" Then
Set rs = db.OpenRecordset("SELECT * FROM `countries`")
' display departments
ElseIf MyFieldStr = "departments_man" Then
Set rs = db.OpenRecordset("SELECT * FROM `departments`")
Else
' No RecordSet has been found and therefor no LoV should be displayed.
db.Close
Set db = Nothing
GoTo NoLoV
End If
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
' Set the number of Columns = number of Fields in recordset
LovForm.ListBox1.ColumnCount = rs.Fields.Count
' Load the ListBox with the retrieved records
LovForm.ListBox1.Column = rs.GetRows(NoOfRecords)
' Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
' display the list of values form
LovForm.Show
'DEBUG MsgBox ("ShowLov " & MyFieldStr)
' Tag to abort procedure and do nothing.
NoLoV:
End Sub
Thanks in advance.