Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / May 2007

Tip: Looking for answers? Try searching our database.

Export to Excel w/ lookup?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
flygal5 - 11 May 2007 00:58 GMT
Various companies with data.  Need to send to Excel.  But in Excel, how can I
do this so that if I pull the company name, data would autopopulate (this
data coming from Access)  Thanks.
Steve - 11 May 2007 02:32 GMT
Please speak in a little more intelligible English so we can understand and
can help you.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
resource@pcdatasheet.com

> Various companies with data.  Need to send to Excel.  But in Excel, how
> can I
> do this so that if I pull the company name, data would autopopulate (this
> data coming from Access)  Thanks.
flygal5 - 11 May 2007 03:23 GMT
Sorry about that.

I have a d/base of accounts:  different companies that have certain data.  
We also have an excel spreadsheet template where we would like to be able to
use the Access d/base info into this excel template.  Is there a way where we
can export the access data to this template so that the company name would be
a dropdown box.  For example, when we select ABC Company, the data
corresponding to ABC would populate the template with corresponding fields in
the access database?

> Please speak in a little more intelligible English so we can understand and
> can help you.
[quoted text clipped - 8 lines]
> > do this so that if I pull the company name, data would autopopulate (this
> > data coming from Access)  Thanks.
John Nurick - 11 May 2007 06:28 GMT
Export from Access in the normal sense, no.

Build an Excel template containing dropdowns and VBA code to make it all
work, yes. This may help: it's an Excel macro that takes the value in
specified cell (or the values in a range), looks it/them up in an Access
table like DLookup(), and places the result(s) in another cell (or
range).

Sub GetData34(Keys As Range, Values As Range, _
 DatabaseName As String, Table As String, _
 KeyField As String, ValueField As String, _
 KeyFieldType As String)

 'Works through all the cells in Keys, looking up each
 'value in Table.KeyField,
 'grabbing the value of ValueField in the same record,
 'and placing it in the corresponding cell in Values.

 'Warning: not yet thoroughly tested. As it stands
 'will fail on text keys that contain apostrophes.

 'Some of this (but not the buggy bits) is based on
 'Allen Browne's ELookup() function.

 Dim dbEngine As Object 'DAO.dbEngine
 Dim db As Object 'DAO.Database
 Dim rs As Object 'DAO.Recordset
 Dim strSql As String
 Dim strKeyValue As String
 Dim j As Long
 
 'Open database
 Set dbEngine = CreateObject("DAO.DBEngine.36")
 Set db = dbEngine.OpenDatabase(DatabaseName)
   
 For j = 1 To Keys.Cells.Count
   'Build the SQL string.
   strSql = "SELECT TOP 1 [" & ValueField & "] FROM [" & _
       Table & "] WHERE [" & KeyField & "] = "
   Select Case LCase(KeyFieldType)
     Case "string", "text", "memo"
       strKeyValue = "'" & Keys.Cells(j).Value & "'"
     Case "date", "time", "date/time"
       strKeyValue = "#" & Format(Keys.Cells(j).Value, _
         "mm/dd/yyyy") & "#"
     Case Else
       strKeyValue = CStr(Keys.Cells(j).Value)
   End Select
   strSql = strSql & strKeyValue & ";"
   Set rs = db.OpenRecordset(strSql, dbOpenForwardOnly)
   If rs.RecordCount = 0 Then
       Values.Cells(j).Formula = ""
   Else
       Values.Cells(j).Formula = rs.Fields(0).Value
   End If
   rs.Close
 Next j

Exit_GetData34:
   Set rs = Nothing
   db.Close
   Set db = Nothing
   Set dbEngine = Nothing
   Exit Sub

Err_GetData34:
   MsgBox "Error in GetData34 at row " & j & ". " & vbCrLf _
       & "Error " & Err.Number & ": " & Err.Description, _
       vbOKOnly + vbExclamation, "Database lookup"
   Resume Exit_GetData34
End Sub

>Sorry about that.
>
[quoted text clipped - 18 lines]
>> > do this so that if I pull the company name, data would autopopulate (this
>> > data coming from Access)  Thanks.

--
John Nurick [Microsoft Access MVP]

Please respond in the newsgroup and not by email.
flygal5 - 11 May 2007 03:24 GMT
Sorry about that.

I have a d/base of accounts:  different companies that have certain data.  
We also have an excel spreadsheet template where we would like to be able to
use the Access d/base info into this excel template.  Is there a way where we
can export the access data to this template so that the company name would be
a dropdown box.  For example, when we select ABC Company, the data
corresponding to ABC would populate the template with corresponding fields in
the access database?

> Please speak in a little more intelligible English so we can understand and
> can help you.
[quoted text clipped - 8 lines]
> > do this so that if I pull the company name, data would autopopulate (this
> > data coming from Access)  Thanks.
John W. Vinson - 11 May 2007 04:26 GMT
>Various companies with data.  Need to send to Excel.  But in Excel, how can I
>do this so that if I pull the company name, data would autopopulate (this
>data coming from Access)  Thanks.

Create a Query joining your data table to the lookup table, and export from
that Query.

            John W. Vinson [MVP]
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.