473,385 Members | 1,465 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.

How to use a variable within SQL code that is embedded in Visual Basic

...Sorry if that question was confusing. Allow me to explain better:

I currently have this line of code:

Expand|Select|Wrap|Line Numbers
  1. Forms!form1.RecordSource = "SELECT * FROM Table1"
My problem is that I have more than one Table I would like to select data from (not just Table1...there is also Table2, Table3, etc). I have a combo box that lists all of my tables and I would like to be able to select a table from the combo box and have the data extracted from the corresponding table.

I was thinking about maybe using some sort of variable but I do not know how to go about doing that. If I were to write it in logic form it would read something like:

let the value of combo1 = $displayTable
Forms!form1.RecordSource = "SELECT * FROM $displayTable"

I'm sure that does no good in code but I hope it helps explain what I am trying to accomplish.

Thanks
Jul 6 '10 #1

✓ answered by patjones

The syntax that you're looking for is this:

Expand|Select|Wrap|Line Numbers
  1. form1.Recordsource = "SELECT * FROM " & Me.combo1

You just need to make sure that when you make a selection from the combo box, it's actually setting the value of the combo box to the string (table name) that you're selecting, and not some numeric value (index).

Pat

1 1152
patjones
931 Expert 512MB
The syntax that you're looking for is this:

Expand|Select|Wrap|Line Numbers
  1. form1.Recordsource = "SELECT * FROM " & Me.combo1

You just need to make sure that when you make a selection from the combo box, it's actually setting the value of the combo box to the string (table name) that you're selecting, and not some numeric value (index).

Pat
Jul 6 '10 #2

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

Similar topics

10
by: John | last post by:
I have a problem, it's not with any code I have because... there is no code. When I run a blank visual basic 6 form, it opens up just fine. When I add a text box, a caption, and a button... it...
3
by: Andreas Klemt | last post by:
Hello, for what is the LABEL good when programming in visual studio like this: Sub xxxx Label1: xxxx xxxx xxx
0
by: Faez | last post by:
i am using Visual Studio 2005 with Visual Basic language. i have a command button, labelled 'SEARCH' and i want to add the following code to the button; so that when people click on the search...
10
by: MCourbois | last post by:
Hi, I'm trying to create a programme which generates a matrix with variable sized rows and columns. Now to reduce the amount of useless code i want to have it so that the labels are automatically...
6
by: Dan | last post by:
Excuse me if i'm being a bit thick here, but is it possible to reference a server side variable within an embedded js source file. For example, my test.js file contains alert('<%=tmpVar%>'); ...
1
by: almira ramos | last post by:
hi friends i have a problem can you give me a code on visual basic that the output looks like this: i need it immediately 1 ...
6
by: Vagabond Software | last post by:
We're talking 2005 for both languages. Left, Top, Right, Bottom, Height, and Width are Integers. C# version: public override int GetHashCode() { return Left ^ ((Top << 13) | (Top >0x13)) ^...
2
by: xlilxmizzxinnocentx | last post by:
Hiya I was woundering if anyone could help me. A few weeks ago i started using vb 5.0 and now im trying to make a code to determine if a word is a palindrome or not. The code that i have tried dose...
0
AHMEDYO
by: AHMEDYO | last post by:
Hi Every one... With this visual Basic 6.0 Code you can handle more event that visual basic Support as Mouse wheel and hover or you can control event before VB IDE Default Windows proc as...
1
praclarush
by: praclarush | last post by:
I’ve tried a verity of different things but I can’t seem to find something that works so I thought I would Ask here, if This is the wrong place then Sorry If you could point me to the correct place...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...

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.