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 / New Users / July 2006

Tip: Looking for answers? Try searching our database.

Using variables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Jones - 30 Jul 2006 09:57 GMT
I am trying to populate a new table (Tbl_MyTable_Temp) with records from an
existing table (Tbl_MyTable).  The records to be included are determined by
one of the fields in the existing table, the value of which is input by the
user.

First I create the new table using an SQL statement as follows:
Dim StrSQL As String
StrSQL = "CREATE TABLE Tbl_Mytable_temp ........
DoCmd.RUNSQL StrSQL

I then use the following code  to enable the user to input a value to a
string variable named Syllabus
Dim Syllabus As String
Syllabus = InputBox("Input Syllabus")

So far so good, but the I try to use the following code to populate
Tbl_Mytable_Temp with records from Tbl_Mytable for which one field [Syllcode]
has the same value as that inout by the user:

Dim StrSQL as String
StrSQL = "INSERT INTO MyTable_temp SELECT MyTable.* FROM MyTable WHERE
[MyTable].[syllcode] = Syllabus ;"
DoCmd.RunSQL StrSQL

However, the variable called Syllabus is not recognised in the SQL
statement.  What am I doing wrong?

Any help would be much appreciated.

Jim Jones
Botswana
Graham R Seach - 30 Jul 2006 11:08 GMT
Jim,

The Jet Expression Service knows nothing about VBA variables, so you have to
supply the *value* of the variable, not its name.

StrSQL = "INSERT INTO MyTable_temp " & _
               "SELECT MyTable.* " & _
                   "FROM MyTable " & _
                   "WHERE [MyTable].[syllcode] = """ & Syllabus & """"

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

>I am trying to populate a new table (Tbl_MyTable_Temp) with records from an
> existing table (Tbl_MyTable).  The records to be included are determined
[quoted text clipped - 30 lines]
> Jim Jones
> Botswana
Jim Jones - 30 Jul 2006 13:35 GMT
Graham

Many thanks for the prompt response.  Your solution worked immediately, and
I can now get on with the job.

I could see that the variable was not being recognized when it was part of
the SQL statement, but finding out how what to do in such circumstances is
difficult for a VBA novice such as myself.  That's why this site is so useful
to folk like me - being able to take advantage of the expertise of MVP's such
as yourself is invaluable.

Many thanks again

Jim Jones
Botswana

> Jim,
>
[quoted text clipped - 46 lines]
> > Jim Jones
> > Botswana
 
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.