VBA code doesn't work if mysql table has unsigned values - mysql

I wrote the vba code below:
For x = 1 To Anno.Options.Length
If Anno.Options(x).Text = CStr(LU(2, CL)) Then
Anno.selectedIndex = x
Exit For
End If
Next x
It takes the values of "LU(2, CL)" (from a query in mySql) and uses it to find the option to activate.
Usually it works, but if I set the values ​​as "unsigned" in the database, no longer works and I get the error: " Variable uses an Automation type not supported in Visual Basic " (This is a translation of the error message in Italian)
Here's my question:
Is there a way to use "unsigned" type with excel?
Edit (clarifications):
LU is an array (type variant) that takes values with: LU = rs.getrows (where rs is a recordset resulted from a query on mySql)
If I modify the MySql database table by setting the field as "unsigned" (I'm talking about one of the fields acquired in LU by the query in the vba code) I get the error.

Related

MS SSIS : Data Type conflict for variables (String vs Object) working with Access MEMO type

I made this package to make my sql task more dynamic:
Step1. I select SQLtext to run from my AccessTable and store in SQLStr var.
Step2. I run that Select statement stored in var SQLStr from Step1.
However I can run Step1 only if I used DataType = Object, and I can run Step2 only if i use DataTYpe = String, I played with it and verified this 100$.
How I can solve this problem, can I do some convert? of datatypes, my query stored in Access DB type = Memo, as it quite long, and might have line breaks.
What is the trick ?? Please refer to pic below for all details.
** Please note that this problem only occurs for Access Memo Type field !!!!**
In other setup it should work with String type OK in Step1
In your first query, when you select SQLText, Cast it as a string (in the select statement) so that you can store it in a string variable.
If it is not possible to CAST the memo field to a string in the SELECT (I'm not familiar with Access), then you can iterate through the object variable in a foreach loop and store the value of the SQLText column in a string variable, and then proceed to step 2 using that.
IF neither of those work, as a brute force method, you can follow the solution in this thread to import the Access table to a Staging table on SQL Server that uses an nvarchar(max) field, which you should be able to select into a string variable with no problem.

how do I use MATLAB for-loop iteration to create MySQL tables?

My MATLAB string variable is
list ={'table1','table2'...}
and I want to create these tables in MYSQL with the code below which is failing;
handle=list;
size_h = max(size(handle));
for i = size_h
e = 'create table handle(i) (col int(11))';
curs=exec(conn,e);
end
I know that the trouble is where I have used my handle(i) in my query, becuase removing that and using a simple table name works as normal.
How would I use my 'i' to create the specific tables?
The issue is you are not passing the actual table names to your connection string, you are rather passing literally handle(i). One alternative is to build the string manually or use the sprintf function. Also handle is a cell and to access it's contents you should use {} instead of (). I also changed the counter from i which stands for the built-in imaginary unit in matlab to ii.
handle=list;
size_h = max(size(handle));
for ii = 1:size_h
e = sprintf('create table %s (col int(11))',handle{ii});
curs=exec(conn,e);
end

When querying a MySql DB VBScript is returning asian characters instead of English

I am using VBScript to query a MySQL database that contains only English characters. The query is basically: SELECT * FROM table name PROCEDURE ANALYSE(1,1)
When I run the query directly on the DB it returns the expected results. However, when the query is run through VBScript it returns gibberish (Chinese?). I know for a fact the DB only contains English as I am the one who built it. I've run numerous other queries against the same table and haven't had any problems. Its only when I run the PROCEDURE ANALYSE query that it returns something unexpected.
The VBScript code is as follows:
strSQLcommand = "SELECT * FROM " & strTempTableName & " PROCEDURE ANALYSE(1,1)"
otRecordset.Open strSQLcommand,Connection
If Not otRecordset.EOF Then
otRecordset.movefirst
Do While NOT otRecordset.EOF
wscript.echo otRecordset(0).value
wscript.echo otRecordset(1).value
otRecordset.Movenext
Loop
End If
I've never had a problem with returning values from any other table in this DB. I've run this query numerous times and always get the same results which has me perplexed.
Any thoughts or ideas are greatly appreciated!
Ok, so, it turns out it has nothing to do with the DB per se.
I decided to start checking the data types that were being returned using the VBScript VarTYpe() method. The fields that were returning "gibberish/Chinese" had a data type of 8092. Basically, a byte array. Sprinkling a little Google fairy dust led me to this function:
Function C8209toStr(body8209)
If VarType(body8209) = 8209 Then
Dim i
ReDim aOut(UBound(body8209))
For i = 1 to UBound(body8209) + 1
aOut(i-1) = chr(ascb(midb(body8209,i,1)))
Next
C8209toStr = Join(aOut, "")
End If
End Function
Hope that helps whoever else comes along!

Comparing string with SmallDateTime used to work

I'm trying to debug an old VB6 program at my job. It's full of bugs and hardcoded stuff.
The program is connecting on a SQL Server 2005 database to read and write info using stored procedures.
Since the program is still being used while I'm working on it, I made a backup of the database to test some things and restored it in my version of SQL Server 2008. Everything was working fine.
When I came in the next morning, I got an error I didn't have the previous night even though the program wasn't used in the night.
The problem :
"exec dbo.sp_Get_Wait_Data '" & DateEx & "'"
DateEx is a string containing "2012/06/14"
The stored procedure :
[sp_Get_Wait_Data] #Datest as char(10)
AS
SELECT
(A lot of column names here)
FROM
Fiche
LEFT JOIN
voyage ON fcid = vofiche
LEFT JOIN
client on fcaccount = cusnov
WHERE
fcdate = #Datest
AND (void is null or (void > 0 and (void <> 999 and void <> 1000 and void <> 998)))
AND ((fcremarques NOT LIKE '%SYSANNULATION%' OR
fcremarques IS NULL)
AND fcrettime IS NOT NULL)
ORDER BY
FcTime, FcOrgSite, fcdessite
The error message :
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value
So the error is here fcdate=#Datest in the stored procedure. I tried adding this line in the stored procedure
SELECT convert(datetime, #Datest, 120)
which worked like a charm for the convertion within the query but caused a few hundred other errors within the program when other queries tried to access this variable so it is not an option.
Any idea why this query was working perfectly yesterday and now it's giving me this error? Thanks in advance.
You probably have set dateformat dmy when connecting to the copy of your database. The date format is set implicitly by the language used. set language.
You could change the format of the parameter to YYYYMMDD which will be safe regardless of set dateformat or even better, change your parameter to datetime.
If that is not an option you can rewrite your query using where fcdate=convert(datetime, #Datest, 111)

Access Query - correct Format for a statement in the MS Access query

I have VBA codes in Access Database. I'm getting an error message "Run Time Error 3464 - Data Type Mismatch in Expression" with the following lines in my codes. What is the correct format of this line? I'm sure its a simple quotation mark or something missing from the line.
Within the Database, there is column called APIC Members. I want only the Records that have "1" listed in the cells.
Table$ = "SELECT * From WHY_Open_Cases_YTD WHERE WHY_Open_Cases_YTD.[APIC Member] = 1;"
Set RST = myDB.OpenRecordset(Table$)
Please advise what I'm doing wrong. When I Debug the message, I get the Set RST = myDB.OpenRecordset (Table$) is highlighted.
On my Access 2003 and 2007 systems, the complete description for error #3464 is "Data type mismatch in criteria expression." The db engine is complaining about the SQL statement you're asking it to use.
If [APIC Member] is text data type instead of numeric data type, add quotes around the value you compare against.
Table$ = "SELECT * From WHY_Open_Cases_YTD WHERE [APIC Member] = '1';"
"Data Type Mismatch" sounds to me as if you are opening the wrong type of Recordset.
myDB.OpenRecordset() expects a DAO.Recordset, and your RST is probably an ADODB.Recordset.
See this answer for a more in-depth explanation:
Open recordset in Access 2003/2007
Try
Table$ = "SELECT * From WHY_Open_Cases_YTD WHERE '[APIC Member]' = '1';"
I had same issue with DAO, and it turns out that it will not accept the SQL query until you have quoted the field name as well.