|
-
May 19th, 2006, 07:46 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Excel and Access
Hello, I have a table in access that has Name, Age, Address, Phone columns. I also have an excel worksheet that has headers for Name, Age, Address, Phone. I have never really done office development before, but how would I go about doing the following?
If I type the Name of someone under the name header, it will automatically pull the rest of the data associated with that name (Age, Address, Phone) from the access database...and put it in the 3 columns to the right of the name in the same row?
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
May 19th, 2006, 08:21 AM
#2
Re: Excel and Access
If you use VBA in excel, you could open an ADO connection with the query
"Select * from tablename where tablename = " & Cells(A,1)
or however you reference a cell in excel.
Then just grab the appropriate column from the resulting dataset
HTH
-
May 19th, 2006, 08:34 AM
#3
Re: Excel and Access
A problem you may encouter when running queries against this table is that Name is a reserved word in both VBA and VB.
If this project is in the beginning states, I would change that to something different, otherwise, in any query in which this field is mentioned, you would need to encapsulate it in brackets, i.e.: [name]
-
May 19th, 2006, 08:37 AM
#4
Thread Starter
Hyperactive Member
Re: Excel and Access
Alright, I have a simple example done...but what is the command to get the current cell your in?
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
May 19th, 2006, 10:01 AM
#5
Re: Excel and Access
I believe
ActiveCell.Value
would reference the current cell
-
May 19th, 2006, 10:04 AM
#6
Thread Starter
Hyperactive Member
Re: Excel and Access
ActiveCel.Value gives me the value of whats in the current cell (ie: "Age"). What I am looking for, is the cells location.
What I am looking for is, if I am in cell A2, and I type "Brandon" and hit enter...I want to know what row and col that I typed it in.
Last edited by LostAngel; May 19th, 2006 at 10:09 AM.
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
May 19th, 2006, 10:06 AM
#7
Re: Excel and Access
Remove the .value and type the . again; you will then see a list of properties/methods relating to ActiveCell - one of which I believe is Row. I'm sure you can work out how to find the column too.
-
May 19th, 2006, 10:10 AM
#8
Re: Excel and Access
I think
ActiveCell.Row
and
ActiveCell.Column
Would reference what you're looking for
I've never used VBA in excel though
*edit* wow, had the reply window open for 4 minutes before submitting aparently
-
May 19th, 2006, 10:19 AM
#9
Thread Starter
Hyperactive Member
Re: Excel and Access
Thank you very much si_the_geek...I feel very dumb as I see the properties are very much like flexgrids and such...
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
May 19th, 2006, 10:50 AM
#10
Thread Starter
Hyperactive Member
Re: Excel and Access
This is my finished code:
VB Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim oRs As ADODB.Recordset
Dim oCnn As ADODB.Connection
Dim oApp As Excel.Application
Dim oWB As Excel.Workbook
Dim i As Integer
'Connect to your Access db
Set oCnn = New ADODB.Connection
oCnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"C:\Documents and Settings\brandone\Desktop\db1.mdb;Persist Security Info=False"
oCnn.Open
'Create your recordset
Set oRs = New ADODB.Recordset
oRs.Open "SELECT Name, Address, Phone, Age FROM tblInfo WHERE Name = '" & Me.Cells(ActiveCell.Row - 1, 1) & "'; ", oCnn, adOpenKeyset, adCmdText
'MsgBox ActiveCell.Row
'oApp.Visible = True
Sheet1.Cells(ActiveCell.Row - 1, 1).CopyFromRecordset oRs
oRs.Close
Set oRs = Nothing
oCnn.Close
Set oCnn = Nothing
End Sub
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|