473,385 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Getting Table/Field value to use in file path

How do you reference the Table:Field to use in a file path? I have been trying the code below

I would like to reference a Tablel:Field to use in the path instead of hard coding the file name, as the name of the file will change between the branches that use it

Expand|Select|Wrap|Line Numbers
  1.     Dim strQryName As String, strXLFile As String, strXLFileName As String
  2.  
  3.     strDB = CurrentDb.Name
  4.     strCurrentDir = Left(strDB, Len(strDB) - Len(Dir(strDB)))
  5.     strXLFileName = ("SELECT [File Name] FROM [Paths] WHERE [Paths].[File Description]= *E-Room*")   
  6.  
  7.     strXLFile = "" & strCurrentDir & strXLFileName & ".xls"    strQryName = "Submit Road Rewards" 'Query Name
  8.  
  9.     Set xlApp = CreateObject("Excel.Application")
  10.     Set wkb = xlApp.Workbooks.Open(strXLFile)
  11.  
For now The Table name is "Paths"
The Field names are "File Name" and "File Description"

Thanks for any help you can give
Jun 15 '10 #1
2 5244
Stewart Ross
2,545 Expert Mod 2GB
@timleonard
Hi. Access provides what it calls Domain Aggregate functions whch can lookup the value of a field within a table, or its sum or average.

Although it is possible to open a recordset using an SQL statement and loop through the recordset to find a specific field value, it is much simpler to use domain aggregate function DLookup to retrieve your filename from table Paths.

Your assignment statement would be changed to:

Expand|Select|Wrap|Line Numbers
  1. strXLFileName = DLookup("[File Name]", "[Paths]", "[File Description]= '*E-Room*'")
DLookup's arguments are string expressions. The first argument is the name of the field you want to lookup, the second is the name of the table or query concerned, and the third (optional) argument is the Where clause being applied (but without the word Where). Note the use of single-colons on either side of the the string literal *E-Room* in the where clause, something you would also have needed in the SQL you provided had this been a viable solution.

-Stewart
Jun 15 '10 #2
@Stewart Ross Inverness
Thanks for the suggestion, Works Great...
I did not think about doing it this way.
Jun 16 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ben | last post by:
Hi all, i have file input field in a form like this: <input name="isbn" type="text" size="25" value="<?php echo $_POST ?>" /> <input name="image" type="file" size="25" value="<?php echo...
10
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
2
by: Bob | last post by:
How do I extract the value of a table field and save it to a variable of similar data type in VBA ? Thank you in advance, Bob.
1
by: MLH | last post by:
Can someone tell me what I'm doing wrong in this query? UPDATE tblEventsSituationsIncidents SET tblEventsSituationsIncidents.ES01 = +1; I'm trying to update the value in table field and am...
3
by: MLH | last post by:
Generally, I do not monkey with renaming controls on forms whose name, by default, matches the name of their related table fields. But I noticed the following today If IsNull(Me!VColor) Then...
6
by: hmiller | last post by:
I am just getting started with VBA and I'd appreciate any help anyone can offer here. I am trying to use VBA to look through the "Curr Year" column in table "tblYear" and check whether the value...
2
by: David - Australia | last post by:
G'day from Australia, I'm hoping some bright spark may be able to help me with this one. I'm sure that it can be done, I've just hit a wall with it. So I'm opening it up. I'm storing student...
1
by: Thinua | last post by:
Hi i'm new to Visual Basic. I have got a copy of vb 6. The problem i have is to get DataReport open a file path with a picture inside it. the file path is stored into a database table field. Can...
1
by: lizarraga | last post by:
I have a table this table sep 2007 = 1.7890 oct 2007 = 1.8952 nov 2007 = 1.8970 in the field (date) sep 2007 the problem is and and other field get 1.7890
2
by: Peter Afonin | last post by:
Hello, I'm new to Crystal reports. Recently I developed my first report, using class as a datasource, and it works OK. But when I created a second report, I started getting error: "Invalid...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.