473,399 Members | 4,177 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,399 software developers and data experts.

Currentdb.execute using string variable

12
Hello,

I have a function "ParseFileName" which removes the ".txt" in the file name which is stored in the variable varItem:

Expand|Select|Wrap|Line Numbers
  1. Public Function ParseFileName(varItem As String) As String
  2.  
  3. x = InStrRev(varItem, "\")
  4.  
  5. sFile = Mid(varItem, x + 1)
  6. sFile = Left(sFile, Len(sFile) - 4)
  7.  
  8. ParseFileName = sFile
  9.  
  10. End Function
I want to use this function to call it so that the remaining part of the file name is stored into my table. So if the filename is 000024-D00.txt from the beginning, i want 0000024-D00 to be stored into the table.

When using this line of code:

Expand|Select|Wrap|Line Numbers
  1. sFile = ParseFileName(CStr(varItem))
  2. CurrentDb.Execute "UPDATE TableData SET BananaField = " & sFile & "  WHERE BananaField Is Null;"
I get error 'too few parameters, expected 1'.

I have been googling trying to seek the answer without success.

sFile is after calling the function ParseFileName = 0000024-D00 as expected.

How do i store this String variable sFile in the table? How do i use a string in the currentdb.execute command?

Thank you
Mar 30 '11 #1
2 8621
Stewart Ross
2,545 Expert Mod 2GB
Hi. When including string literal values (in this case from the value stored in variable sFile) you must enclose the text using single quotes just before and after that part of the string, like this:

Expand|Select|Wrap|Line Numbers
  1. CurrentDb.Execute "UPDATE TableData SET BananaField = '" & sFile & "'  WHERE BananaField Is Null;"
-Stewart
Mar 30 '11 #2
Higgs
12
amazing, thank u so much!

If u only knew how much time i have spent trying figuring this out.

So simple yet so hard.

Thanks a million
Mar 30 '11 #3

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

Similar topics

2
by: Himaxda0 | last post by:
Is it possible to access Objects like (document.form1.textfield1) with a string variable like (var obName='textfield1') and using (document.form1.obName.value)? Ive tried it in IE but the value in...
9
by: Stefan Mueller | last post by:
I'd like to set a variable called 'FocusIsOn' if a button got the focus. Because my button is dynamically created I do it like xelement = document.createElement("input") xelement.type = "button"...
6
by: Doohan W. | last post by:
Hi, I'm now working with DB2, and I can't find out how to execute the contents of a string Statement, without using a Java/... procedure, only using SQL statements. I know that some SQBDs such...
1
by: Martin Heal | last post by:
I am having problems trying to assign the contents of a Memo table field to a String variable in VB using the following code: Private Function udfBuildSQL(SQLID As Integer) As Variant Dim rs...
1
by: GSteven | last post by:
I have a statemnt which says: CurrentDb.Execute strSQL, dbFailOnError where strSQL is a create query. Is there an overwrite option for the execute method so thath I don't get the 'file already...
1
by: Hose B | last post by:
HI all, I have a legacy app in which users can pick various page templates. There is a template preview dialog. It works such that they view a list of icons in an asp page that represent each...
1
by: neo1981 | last post by:
I want to execute code which is in a string variable like if i have a string like str='import xyz' then I want to execute import xyz in my program. Is there any way to do this ? :confused:
1
MitchR
by: MitchR | last post by:
Hello Folks; I have run myself into a hole I cannot get of and need some assistance. I have a Form "Frm_ATandT_Activation_Center" that has a sub form "Frm_ATandT_Activation"....
13
by: matt753 | last post by:
Can anyone tell me whats wrong with this SQL statement? CurrentDb.Execute("INSERT INTO Joblist2Data (ID, DayUsed, Employee, Priority, Item, Task, Comments, Complete) VALUES (" & Null & ", #" & 5 /...
0
by: sama123 | last post by:
Is it possible to save execute stored proc command in a string variable and then execute string variable??? Does this logic fits into LINQ2SQL? Why I want to do this - INstead of passing user...
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: 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
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: 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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.