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

SQL Question - I am nearly there!

The following code works:

Function CopyDB(TableName)

Dim str, str2, intlen, str3, str4, strFileName
str = Trim(DLookup("[DataPath]", "CurrentUser"))
For intlen = Len(str) To 1 Step -1
str2 = str2 & Mid$(str, intlen, 1)
Next intlen
str3 = InStr(str2, "\")
str4 = Left(str2, str3 - 1)
strFileName = ""
str2 = ""
For intlen = Len(str4) To 1 Step -1
strFileName = strFileName & Mid$(str4, intlen, 1)
Next intlen
Dim x As String
x = DLookup("[DataPath]", "CurrentUser")
Dim strSQL As String
Dim Db As Database
Set Db = CurrentDb
strSQL = "SELECT tblProducts.* INTO TableName IN "
strSQL = strSQL & strFileName
strSQL = strSQL & " FROM tblProducts;"
Db.Execute strSQL, dbFailOnError
End Function

It parses str and copies tblProducts to TableName and puts TableName
into the Database represented by strFileName.

I creates a new table called TableName

How can I make TableName a variable so that it can take the actual
name of the new table being passed to the function?
Thanks
Patrick

Nov 13 '05 #1
2 1207
Try:
strSQL = "SELECT tblProducts.* INTO [" & TableName & "] IN " & _
strFileName & " FROM tblProducts;"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Patrick Fisher" <in**@psoftuk.com> wrote in message
news:3r********************************@4ax.com...
The following code works:

Function CopyDB(TableName)

Dim str, str2, intlen, str3, str4, strFileName
str = Trim(DLookup("[DataPath]", "CurrentUser"))
For intlen = Len(str) To 1 Step -1
str2 = str2 & Mid$(str, intlen, 1)
Next intlen
str3 = InStr(str2, "\")
str4 = Left(str2, str3 - 1)
strFileName = ""
str2 = ""
For intlen = Len(str4) To 1 Step -1
strFileName = strFileName & Mid$(str4, intlen, 1)
Next intlen
Dim x As String
x = DLookup("[DataPath]", "CurrentUser")
Dim strSQL As String
Dim Db As Database
Set Db = CurrentDb
strSQL = "SELECT tblProducts.* INTO TableName IN "
strSQL = strSQL & strFileName
strSQL = strSQL & " FROM tblProducts;"
Db.Execute strSQL, dbFailOnError
End Function

It parses str and copies tblProducts to TableName and puts TableName
into the Database represented by strFileName.

I creates a new table called TableName

How can I make TableName a variable so that it can take the actual
name of the new table being passed to the function?
Thanks
Patrick

Nov 13 '05 #2
Thanks Allen
That worked fine
Patrick

On Wed, 24 Nov 2004 16:56:07 GMT, Patrick Fisher <in**@psoftuk.com>
wrote:
The following code works:

Function CopyDB(TableName)

Dim str, str2, intlen, str3, str4, strFileName
str = Trim(DLookup("[DataPath]", "CurrentUser"))
For intlen = Len(str) To 1 Step -1
str2 = str2 & Mid$(str, intlen, 1)
Next intlen
str3 = InStr(str2, "\")
str4 = Left(str2, str3 - 1)
strFileName = ""
str2 = ""
For intlen = Len(str4) To 1 Step -1
strFileName = strFileName & Mid$(str4, intlen, 1)
Next intlen
Dim x As String
x = DLookup("[DataPath]", "CurrentUser")
Dim strSQL As String
Dim Db As Database
Set Db = CurrentDb
strSQL = "SELECT tblProducts.* INTO TableName IN "
strSQL = strSQL & strFileName
strSQL = strSQL & " FROM tblProducts;"
Db.Execute strSQL, dbFailOnError
End Function

It parses str and copies tblProducts to TableName and puts TableName
into the Database represented by strFileName.

I creates a new table called TableName

How can I make TableName a variable so that it can take the actual
name of the new table being passed to the function?
Thanks
Patrick


Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
6
by: Nick Dreyer | last post by:
In VB.NET I would like to not have to create property get/set procedures for every class variable I want to expose to Excel VBA projects in COM builds. Can anyone tell me if that is possible, or...
7
by: Office Drone | last post by:
I'm a bit confused about memory usage, and for some reason I wasn't able to find a single point-of-call to get the amount of memory available. If we take, for instance, the Windows platform: ...
39
by: Antoon Pardon | last post by:
I was wondering how people would feel if the cmp function and the __cmp__ method would be a bit more generalised. The problem now is that the cmp protocol has no way to indicate two objects are...
5
by: John | last post by:
Hi On MSDN feedback site there are way more bugs/suggestions being closed than are being submitted each week. Does this mean we are at the need of the tunnel? Thanks Regards
9
by: Alberto | last post by:
Eh unfortunately Google groups does not provide any longer a way to reply to the group for older posts (though the one I am referring to is not older than one month), and I happen to come back to...
44
by: Tolga | last post by:
As far as I know, Perl is known as "there are many ways to do something" and Python is known as "there is only one way". Could you please explain this? How is this possible and is it *really* a...
1
by: spgedwards | last post by:
I am trying to run a basic script that displays an existing jpeg image and writes some text over it. Sounds simple, but I cannot seem to be able to colour the font correctly. In the example below...
5
by: jasone | last post by:
Hi all, im nearly there with this one and im sure it shouldnt be hard to solve, i just cant seem to find the solution. ive got records being displayed, the user can then tick what records to...
0
by: tschroeder250 | last post by:
Hi Everyone, There are so many Nullable DateTimePickers out there that this post may not even be found among all the others, but I wanted to try. First, I want to thank all the authors of the...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.