K
Kerri
Hi,
I'm in Word 2003 and I have TWO DAO excel spreadsheets that I want to
use in my VBA User Form. One is the Authors information (Name,
initials, email, title, phone, location...) . That pulls the correct
info into the fields of the form. The cmbOfficeLocation.valule field
is the field the second database needs to access in order to insert
the correct address in the document.
The second database includes the office locations info (Branch,
Address, City...Phone, etc.)
I tried to pull the second database into the cmbOfficeLocatoin.value
field. and it works fine as long as the author/location doesn't
change. Then the .column 7 properly refers to the second table when I
want it to refer to the first table.
How do I get it to pull the data from one data record into the next
data record?
"Phoenix" = "Phoenix"
cmbLOCATION.Value = cmbOfficeLocation.Value
I get: "602-111-1111" = "Phoenix"
Because the phone is referenced in Column 7 of the Location database
and Phoenix is referenced in column 7 of the Authors database.
Thank you for your time.
Kerri
Private Sub UserForm_Initialize()
'loads the Data info
'=====Load Authors data from Excel table=====
'This populates the combo box for Office Location
cmbOfficeLocation.AddItem "Colorado Springs"
cmbOfficeLocation.AddItem "Denver"
cmbOfficeLocation.AddItem "Phoenix"
cmbOfficeLocation.AddItem "Scottsdale"
cmbOfficeLocation.AddItem "St. Louis"
cmbOfficeLocation.AddItem "Steamboat Springs"
cmbOfficeLocation.AddItem "Vail"
'Contains a list of Authors and preferences
'NOTE: Must Reference "Microsoft DAO 3.6 Object Library" by going to
"Tools | References..." for Word 2003
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
' Open the database
Set db = OpenDatabase("c:\_Auth\AuthList.xls", False, False,
"Excel 8.0")
' Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `Authors`") '**Authors is
Named Range in the Excel Spreadsheet.
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
' Set the number of Columns = number of Fields in recordset
cmbAuthorsInitials.ColumnCount = rs.Fields.Count
' Load the ListBox with the retrieved records
cmbAuthorsInitials.Column = rs.GetRows(NoOfRecords)
' Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
'=======End Authors Excel Datafile=================
End Sub
I'm in Word 2003 and I have TWO DAO excel spreadsheets that I want to
use in my VBA User Form. One is the Authors information (Name,
initials, email, title, phone, location...) . That pulls the correct
info into the fields of the form. The cmbOfficeLocation.valule field
is the field the second database needs to access in order to insert
the correct address in the document.
The second database includes the office locations info (Branch,
Address, City...Phone, etc.)
I tried to pull the second database into the cmbOfficeLocatoin.value
field. and it works fine as long as the author/location doesn't
change. Then the .column 7 properly refers to the second table when I
want it to refer to the first table.
How do I get it to pull the data from one data record into the next
data record?
"Phoenix" = "Phoenix"
cmbLOCATION.Value = cmbOfficeLocation.Value
I get: "602-111-1111" = "Phoenix"
Because the phone is referenced in Column 7 of the Location database
and Phoenix is referenced in column 7 of the Authors database.
Thank you for your time.
Kerri
Private Sub UserForm_Initialize()
'loads the Data info
'=====Load Authors data from Excel table=====
'This populates the combo box for Office Location
cmbOfficeLocation.AddItem "Colorado Springs"
cmbOfficeLocation.AddItem "Denver"
cmbOfficeLocation.AddItem "Phoenix"
cmbOfficeLocation.AddItem "Scottsdale"
cmbOfficeLocation.AddItem "St. Louis"
cmbOfficeLocation.AddItem "Steamboat Springs"
cmbOfficeLocation.AddItem "Vail"
'Contains a list of Authors and preferences
'NOTE: Must Reference "Microsoft DAO 3.6 Object Library" by going to
"Tools | References..." for Word 2003
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
' Open the database
Set db = OpenDatabase("c:\_Auth\AuthList.xls", False, False,
"Excel 8.0")
' Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `Authors`") '**Authors is
Named Range in the Excel Spreadsheet.
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
' Set the number of Columns = number of Fields in recordset
cmbAuthorsInitials.ColumnCount = rs.Fields.Count
' Load the ListBox with the retrieved records
cmbAuthorsInitials.Column = rs.GetRows(NoOfRecords)
' Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
'=======End Authors Excel Datafile=================
End Sub