I am doing a simple select query in Access 2010 using the design view. My source file is an excel worksheet that I have linked to a table in Access. I can view the source, but am not able to modify it in any way.
One of the columns in the source file can have the following error: "#NAME?"
When I see an error, I just want to read the value in as an empty string "", but when there isn't an error, I just want the value. I've researched different variations of using Nz, IIF, Switch, and IsError but haven't had any success yet.
I am trying the following code in the "Field" parameter in design view.
Program_Temp: IIf(IsError([Program]), "", [Program])
This fails because IIf evaluates both the "truepart" and the "falsepart" so even if the error is properly detected, the function will be in error because "[Program]" is still evaluated.
Is there a way to achieve this?
The Excel will pass the values as string to the access.
Now you just have to use the replace the error with empty string.
Replace ( string1, find, replacement, [start, [count, [compare]]] )
Replace ( Program_Temp, "#NAME?", "" )
or
Replace ( Program_Temp, "#NAME?", vbnull )
Also I will suggest the same thing as #serakfalcon. Import the table, not link it, and when new info is needed, delete the data and import new data. A nice side-effect of this is that errors will be replaced by null.
Related
I'm receiving a compile error attempting to run a query using Allen Browne's ConcatRelated function.
Compile error: in query expression 'SELECT MbrNbr, EventIndex, ConcatRelated("EventIndex", "PlayerResults", MbrNbr = 123456)'.
The mystery is I know this executed successfully previously.
Note: This is my first time using MS Access for a project, so it's my first time using Allen's ConcatRelated function. I have to assume there is something obvious I'm missing. I've coded in MS Excel VBA for about 10 years.
I do have a query that is more complex than the example below but I put together this very basic query just to test if there is something amiss with my setup all of a sudden.
I've googled all I can to attempt to resolve this and all code examples seem to show I have it correct.
Setup:
ConcatRelated is saved as a function named Concat_Related_Data. I've read the function name cannot be ConcatRelated.
The simple query receiving the error is:
SELECT MbrNbr, EventIndex, ConcatRelated("EventIndex", "PlayerResults", MbrNbr = 123456)
FROM PlayerResults;
Note: I copied Allen's example and simply edited it with a call to one of my tables. Field MbrNbr is defined as "Number".
Any insights would be greatly appreciated!
After taking a look here http://allenbrowne.com/func-concat.html I saw that the third parameter is defined as a string parameter too (as expected) and not as a boolean.
So I think you should use this:
SELECT MbrNbr, EventIndex, ConcatRelated("EventIndex", "PlayerResults", "MbrNbr = 123456") FROM PlayerResults;
Info: The third parameter of ConcatRelated also is a string here, containing your condition.
In addition to the answer provided by #UnhandledException; where you state:
ConcatRelated is saved as a function named Concat_Related_Data.
I've read the function name cannot be ConcatRelated.
For clarity: the code for the function should be copied "as is" from Allen Browne's site into a new VBA module, without changing the function name.
However, when saving the VBA module, the module should be named something different to ConcatRelated, else you will receive a type-mismatch error when trying to invoke the function.
Note that if you are using the code within SQL code that is represented using a string in VBA, you will need to either escape the double-quotes (to ensure that they remain in the SQL code), or use single-quotes instead, i.e.:
CurrentDb.OpenRecordset("SELECT MbrNbr, EventIndex, ConcatRelated('EventIndex', 'PlayerResults', 'MbrNbr = 123456') FROM PlayerResults")
Or:
CurrentDb.OpenRecordset("SELECT MbrNbr, EventIndex, ConcatRelated('EventIndex', 'PlayerResults', 'MbrNbr = 123456') FROM PlayerResults")
I am using a Data Macro for one of my Access table's after insert event. Inside this Data Macro, I am using SetLocalVar to call one of my functions written in vba to insert the same inserted record set into my SQL Database. This is how the Expression in SetLocalVar currently looks like;
AfterInsertMacro("TblLotStatus",[LotStatusID], [NextStatus], [Status], [Printed], [Active], [AvailableForPull] )
Now, instead of returning back every column as a separate variable, can't I return a record set or a collection or an array etc. ?
Basically I am looking for something like this (written in C# language);
AfterInsertMacro("TblLotStatus", new object[]{[LotStatusID], [NextStatus], [Status], [Printed], [Active], [AvailableForPull]} )
Or any kind of expression that would look like;
AfterInsertMacro("TblLotStatus", [Inserted Recordset])
I am new to the Business Objects Data services.
I have to run a dataflow reading from a file. Filename should be read based on wild chars like Platform. And I want to run the dataflow only if the file exists, if file is not present , it should not error out or should not do anything but it should just move on to the next dataflow or workflow in the job.
I tried below code to check if the file exists as built_in function File_Exists cannot check the file based on wild chars.
*$FILEEXISTSFLAG= exec('/bin/ksh',' "ls xxxxxx/Platform.csv',8);*
My intention is based on the value assigned to $FILEEXISTSFLAG from above code, I will decide whether to execute the data flow or not (if $FILEEXISTSFLAG is null do nothing otherwise execute the data flow ) but its retrieving below output.
*ls: cannot access /xxxxxx/Platform.csv: No such file*
Is there any other way to achieve this?
I was able to solve the above problem by using the index function.
$FILEEXISTSFLAG is containing a value like "ls: cannot access Platform: No such file or directory ". So, I have used the index function as below. So if the output is not null for below index function, it will execute the dataflow, otherwise it will do nothing.
index( $FILEEXISTSFLAG , 'No such file',1)
Thanks,
Phani.
I have a problem that I have been trying to solve for a couple of days with MS Access and a VBA function.
To start I have a table as follows
Name = Team
fields are mostly text bases, unless stated otherwise
ID(autonumber primary key)
Non
Prenom
Location
TeamID (created by concatenting the Nom, Prenom and Location fields)
On my form I would like to extract the partial details entered into the Nom, Prenom, and Location fields. Then pass this back to the Database to enter into the TeamID field for the individual.
The extraction should take the form of
TeamID = mid(Location,0,4) & mid(Prenom,0,2) & mid(Nom,0,2à)
However I realise that I can't put this into the 'controle source' section of the properties for any field.
So after much searching I decided that I should use a function in a separate module (I do this concatenating quite often for creation of 'sensible' index values on a large number of my tables, I find the autonumber primary key not very user friendly, or self explanatory.
So in my database file I created a module (called getInfo) with the public function
Public Function getID() As String
Dim r As String
Dim i As String
i = "Twenty"
Below are some of the options I have tried....
'r = VBA.Strings.UCase$(String:=i) 'turning the value of i to uppercase
getID = r 'returns "TWENTY" as expected
or
'r = VBA.Strings.Mid$("TWENTY", 0, 2)
getID = r 'error and highlights above line?
or
'r = StrReverse(i)
getID= r 'again error and highlights above line
getID = VBA.Strings.Mid$(String:="TWENTY", Start:=0, Length:=2)
End Function
I then opent eh 'execution' window and run the function.
I seem to be only able to convert the value to upper or lower case, any searching or manipulation of the string just gives me a message bow with the following error
Execution Error '5'
argument or procedure call incorrect
(please bear with me I am working on a french terminal and so my translation of this error may not be very acurate).
However all the functions come up correctly when I type them, as do the parameters being passed. when I search the net the info is also the same
http://www.techonthenet.com/excel/formulas/index_vba.php
So I am lost as to where I am going wrong.
I guess I am not declaring the value of my variables correctly, but I can't see why.
This code doesn't work elsewhere (other terminals) either, so I'm sure it must be my error!
But what is it.
I feel that this is a reallybasic problem, but just can't get the function to work when manipulating a string.
Do I need to call this function from a sub only, and not directly, will this be the same on my form page?
I can create a minidatabase with just this code in if required.
You should not need the VBA.String namespace prefix, and the ArgName:= syntax is optional so long as you follow same-order rules for optional paramaters.
Mid$("TWENTY", 0, 2) fails because in VBA strings start at index 1, so Mid$("TWENTY", 1, 2) would return TW
hello i am new to SSIS and iam receiving text file created by SSIS iam using wizard to load it to oracle table but in the text file there is columns contain the String NULL and other contain blank string instead of zero length column is there an auto way to make these value to become actual null value in the table or do i have to create derived column for each one of theses cases
thank you,
Within an SSIS project in the SQL Server Data Tools for Visual Studio 2015/SQL Server 2016, the way to address the handling of empty columns seems to be via a property of the Flat File Source component (not certain whether space-only columns qualify):
Right-click the Flat File Source and choose Show Advanced Editor....
Select the Component Properties tab.
Set RetainNulls property to True (default is False).
If you want to convert the value into null if your input value in empty/blank, then you can try (under assumption datatype is of string/varchar) :
LEN(TRIM([ColumnName]))==0 ? NULL(DT_WSTR, 10) : [ColumnName]
I faced the same issue, you can use a script component and add the code below to loop through all the columns and replace each text null with actual null value...
foreach (PropertyInfo dataColumn in Row.GetType().GetProperties())
{
if (dataColumn.Name.ToLower().EndsWith("_isnull") == false && dataColumn.PropertyType == typeof(string))
{
object objValue = dataColumn.GetValue(Row, null);
if (objValue != null && objValue.ToString() == 'NULL')
{
dataColumn.SetValue(Row, null, null);
}
}
}
Code explanation is here
If you're using SSIS 2008, there's also the Null Manager component from Tactek Data Systems. It isn't free, but it's pretty cheap - like $10 bucks. (www.tactek.com). You can convert empty strings to nulls, nulls to empty strings, and nulls to "filler" values like "Unknown" or "NA".
I don't think there is any way to do this using the standard Flat File Source SSIS provides. To do this I make use of a custom component called Delimited File Source, which can be downloaded here: http://ssisdfs.codeplex.com/. As its name indicates, it's also much better at handling delimited files, plus it has the option of treating empty strings as NULL.