473,396 Members | 1,884 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,396 software developers and data experts.

How do you generically reference fields in VBA?

Thanks in advance for your help!

I have a loop that assigns the name of a table to the variable "a" I want to use a sequel statement to access the contents of this table and have it ordered according to the first field before several other actions are performed. What is the best way to do this?

This is what I am trying, but am not sure if this is technically correct:


Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM [" & a & "] ORDER BY 'Fields(0)' ASC"
Mar 1 '11 #1

✓ answered by pod

looks ok to me ... try it and let us know

you can also make use of a SELECT/CASE for specific tables and fields

Expand|Select|Wrap|Line Numbers
  1. SELECT CASE a
  2.    CASE "projectTBL"
  3.       FLD = "projectNumber"
  4.    CASE "ClientTBL"
  5.       FLD = "ClientName"
  6.    CASE ELSE
  7.       ... 
  8. END SELECT
  9. strSQL = "SELECT * FROM [" & a & "] ORDER BY " & FLD  & " ASC"
  10.  

3 1502
pod
298 100+
looks ok to me ... try it and let us know

you can also make use of a SELECT/CASE for specific tables and fields

Expand|Select|Wrap|Line Numbers
  1. SELECT CASE a
  2.    CASE "projectTBL"
  3.       FLD = "projectNumber"
  4.    CASE "ClientTBL"
  5.       FLD = "ClientName"
  6.    CASE ELSE
  7.       ... 
  8. END SELECT
  9. strSQL = "SELECT * FROM [" & a & "] ORDER BY " & FLD  & " ASC"
  10.  
Mar 1 '11 #2
Thanks POD -- clever trick with the case selection for FLD!
Mar 1 '11 #3
pod
298 100+
You are welcome BG

Bytes is full of clever tricks and members

P;oD
Mar 1 '11 #4

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

Similar topics

15
by: David Fisher | last post by:
I have been encouraged by someone else to use a reference rather than a pointer as an "out" parameter to a function, eg. void doStuff(Thing &out1, Thing &out2) as opposed to: void...
3
by: Tomislav Bartolin | last post by:
Hi I'm trying do create a generic base class for all of my data objects. One of the main requirements for this class is to be able to handle all common db actions without need for implementing...
12
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL...
3
by: Ross McLean | last post by:
Hi all, I've been teaching myself C# for a new project at work. I have a bit of a background in c++ and java but never been what you could call a guru. I'm having some strange things happening...
2
by: danielle.m.manning | last post by:
I have a question about a problem I am having with attempting to port some old ASP code to ASP.NET. We have a dll out there which we downloaded which creates GUIDs for session management. In...
2
by: RLN | last post by:
I have this error message format I use for my error handling in all modules, both in vba code inside of a form and vba code that is outside of forms: MsgBox Err.Number & "-" & Err.Description,...
1
by: beat1078 | last post by:
I have a table with information about an individual and their supervisory chain and what job title the employee is. If done correctly the top of the supervisory chain will be entered in first and...
4
by: Rotsey | last post by:
Hi, I have written a custom multi column listbox control that I pass a datatable to. the issue is that if there are date fields then these may be in the wrong format or any other field...
4
by: call_me_anything | last post by:
I have different kind of data structures in different applications. The data structures are big and complex and I would like to print the members of each struct. Can we write a generic piece of...
1
by: PeterAPIIT | last post by:
What is template template arguments and template typename arguments ? The reason i write in policy based design is because this is the requirement of the assignment. My code so far: ...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.