I have an Access Database that is reading data from a SharePoint list,
then outputting the data into an excel spreadsheet There are many queries involved, about 40 total.
Here is the format of each query:
Set qdf20 = db.QueryDefs("<Query Name Here>")
qdf20!Param1 = Param
Set rst20 = qdf20.OpenRecordset()
qdf20.Close
rst20.Close
Set qdf20 = Nothing
Set rst20 = Nothing
This is in a 'For' loop, and the 'Param' changes with each iteration of the loop.
The problem: Some queries work, and some do not. The only thing that is changed
is the query name, the record set name and the query def name. The errors are
totally random. The parameters are in an array, and the for the queries that work,
all the parameters are successfully transferred.
Solutions I have tried are using the Parameters Collection Object, and using the SQL commands directly in VBA, but that didn't help. The error I receive is: "Too few parameters, expected 1". I have read the other posts concerning this same error, but they do not solve the problem.
I'm at my wits-end trying to find a solution. Can anyone offer any insight?
It would be very helpful and much appreciated.
Related
I am running a PowerShell script using System.Management.Automation, and the script runs fine.
I am then pulling the results from the script using the command below and I can see the results in my variable sResults when looking at it in the debugger.
Dim sResults = ps.Runspace.SessionStateProxy.GetVariable("results")
And I can loop through each item in SResults using
For Each sResult In sResults
But I can't work out how to actually obtain any of the values stored in this variable within my code, I have tried using TryCast to convert it to a PSObject, but still at a loss.
As you can see in the screenshot below all the information I want is there, I just need to know how to get it out, namely the value of Exception and PSComputerName (or) TargetObject initially.
Any help would be much appreciated, spent hours search forums and googling etc but can't seem to find much reference to GetVariable or similar issues.
Answered by very helpful person here :) = https://community.spiceworks.com/topic/2459073-how-to-access-values-from-runspace-sessionstateproxy-getvariable
I am trying to run an update query but it is giving me "Data type mismatch in criteria expression". It was working just fine before but now, all of sudden it started giving me this error. I tried doing research and also checked in stack overflow but could not find the solution. I only have one criteria expression in my query.
UPDATE dbo_tblGoods INNER JOIN qryValidate
ON dbo_tblGoods.MaterialID = qryValidate.MaterialID
SET dbo_tblGoods.BarcodeType = [qryValidate]![BarCodeType],
dbo_tblGoods.BarCode = [qryValidate]![BarCode]
WHERE (((Right$([NewBarCode],4))="GOOD"));
Also, qryValidate is:
SELECT Parts.MaterialID, Validate_UPC([Parts]![Barcode],[Parts]![BarcodeType]) AS NewBarCode,
Parts.BarCodeType, Parts.BarCode
FROM dbo_tblgoods INNER JOIN Parts
ON dbo_tblgoods.MaterialID = Parts.MaterialID;
Whenever I got the error "Data type mismatch, I always check those fields I have with expression "=,>.." or Function. Most likely, the cause of the error is a Null field.
Try to check your function Validate_UPC([Parts]![Barcode],[Parts]![BarcodeType]) and change it to Validate_UPC(nz([Parts]![Barcode]),nz([Parts]![BarcodeType])) for Null fields.
If it doesn't work, then go check if the parameters in Validate_UPC matches the data type you supplied in your query. e.g. If you declared Barcode as Integer, a string field is not valid. Try to declare the Barcode or BarcodeType as Variant and properly handle them in VBA.
Lastly, you are trying to inner join fields on two or more tables that are not of the same data field types. I often make this mistake when I create new temporary tables out of data imports(e.g. excel imports)
I have an excel sheet with 15k data and I realized there were 2 cells which were empty. Therefore, it was giving me this error. Thank you all for trying to help me out.
I am currently half way through a project where I am migrating data from an ancient Adobe Workflow server using Visual Basic and COM.
I have hit a bit of a brick wall really as I am trying to perform a simple while loop that counts the number of records in a recordset, and I keep getting this error...
"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in microsoft.visualbasic.dll
Additional information: Unspecified error"
There is little to no documentation to help me online so I am hoping there is some sort of VB wizard/veteran that can point me in the right direction.
I have set the record as a global variable like so...
Dim record As New EPSDK.Recordset
I have then tried...
Dim recCount As Integer = 0
Do Until record.EOF
recCount += 1
Loop
This...
Dim recCount As Integer = 0
Do While Not record.EOF
recCount += 1
Loop
This...
Dim recCount As Integer = 0
Do
recCount += 1
Loop Until record.EOF
And lots of other variations, but still cannot seem to source the problem. There are no code errors, nothing comes up in the console, and I just keep getting that message back.
Can anyone spot what I am doing wrong? Thanks
Ok, I've looked up the documentation for EPSDK. For those who are unaware (as I was), it's an object collection from Adobe for manipulating COM data. It's basically the most popular functionality in ADO.
MoveFirst, as its name suggests, moves to the first record in a recordset. There doesn't appear to be any such method supported by the EPSDK Recordset object. Since you can use the Move method to do the same thing, it isn't needed. In either case, you don't need to use it to move to the end of the file.
What you're doing wrong is expecting that you can increment a variable called recCount that you made up and the recordset cursor will magically move along. Doesn't happen. As you say, the doc is insubstantial, but you probably need to use MoveNext. Here's a cheat sheet you can use to look up what's supported.
Also, you need to specify a connection, open it, point the recordset to the open connection, and open the recordset. I would suggest that you familiarize yourself with ADO (NOT ADO.Net! Not the same thing), upon which this is clearly based. There's much more documentation, and it should apply fairly well. Read up on Connections and Recordsets in particular.
Now, your loops do pretty much the same thing. While Not is the equivalent of Until. However, if you put the while/until condition after the Do statement, you won't enter the loop unless the condition is met. If you put it after the Loop statement, you will always run the loop at least once. In this case, you should put "Do Until myRecordset.EOF", because then if the recordset is empty, you won't go into the loop.
I think all I need is to somehow unbind the stored procedure recordset to the Janus GridEX, but having a difficult time figuring out how. Programming language is VBA.
My grid populates as I want - no problem there. But this code will not allow me to edit the cells that I have showing (hiding some columns):
JGEX.AllowEdit = True
JGEX.Columns(4).EditType = jgexEditNone
JGEX.Columns(6).EditType = jgexEditTextBox
JGEX.Columns(7).EditType = jgexEditTextBox
JGEX.Columns(8).EditType = jgexEditTextBox
again - I think the only issue is the need to disconnect the recordset (to allow edit). The RS object is tied in like this:
Set JGEX.ADORecordset = rsStaged
Where the rsStaged is this:
Set rsStaged = New ADODB.Recordset
rsStaged.CursorLocation = adUseClient
rsStaged.Open SQL1, cnScada, adOpenStatic, adLockOptimistic
Pretty simple recordset, but comes from a stored procedure, not a direct table query.
Thanks in advance!
I fixed the issue by adding lines of code as shown below:
JGEX.AllowEdit = True
JGEX.EditMode = jgexEditModeOn
JGEX.Columns(4).EditType = jgexEditNone
JGEX.Columns(6).EditType = jgexEditTextBox
JGEX.Columns(7).EditType = jgexEditTextBox
JGEX.Columns(8).EditType = jgexEditTextBox
JGEX.Update
You can see the differences there from above. My only problem now is that when I actually edit fields (complete on a single row), I would get this:
Multiple-step operation generated errors. Check each status value.
I believe this issue is because my recordset object is bound and it is attempting to write back. Essentially, though, what I want to do is have the ability to update any row inside the table. I will handle write back by iterating through the rows and then calling a Stored Procedure as required.
thanks again.
I'm trying to write code that talks to Google Spreadsheets. We do a bunch of processing on our end and then pass data out to our client into this spreadsheet and I want to automate it. This seems like it should be easy.
On this page, Google says "Given a SpreadsheetEntry you've already retrieved, you can print a list of all worksheets in this spreadsheet as follows:"
AtomLink link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);
WorksheetQuery query = new WorksheetQuery(link.HRef.ToString());
WorksheetFeed feed = service.Query(query);
foreach (WorksheetEntry worksheet in feed.Entries)
{
Console.WriteLine(worksheet.Title.Text);
}
Following along at home, I start with:
Dim link As AtomLink = Entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, "")
Dim wsq As New WorksheetQuery(link.HRef.ToString)
and when execution gets to that second line, I find that "Object reference not set to instance of an object." The FindService method is returning nothing. And when I look at GDataSpreadsheetsNameTable.WorksheetRel, it's a constant value of "http://schemas.google.com/spreadsheets/2006#worksheetsfeed"
I'm not really at the point where I even grok what it wants to be doing. E.g., what's a feed? Is a worksheet really what I think it is based on Excel nomenclature? That kind of stuff. But I see a couple of things that might be causing my issue:
The C# method call "...FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);" I'm not sure about that null. It demands a string, so I used "" in my VB, but I'm not sure that's right.
That schemas.google.com URI doesn't seem to be live. At least, if I punch it into a browser, I get server not found. But again, I don't exactly know what it's trying to do.
So, any thoughts? Anyone have VB code that reads Google Spreadsheets and time to instruct a newbie? I'm surprised to find that there's essentially no useful sample code floating around the net.
Thanks for reading!
So, of course, right after I posted this I found some inspiration over here. Manually iterating across the collections works just fine, even if it's not the preferred way to do this. I'm still keen to hear info from others related to this, so feel encouraged to help out even though I'm maybe over this one hurdle.
For Each Entry In mySprShFeed.Entries
If Entry.Title.Text = "spreadsheetNameSought" Then
For Each link As AtomLink In Entry.Links
If link.Rel = GDataSpreadsheetsNameTable.WorksheetRel Then
Dim wsf As WorksheetFeed = service.Query(New WorksheetQuery(link.HRef.ToString))
For Each worksheet In wsf.Entries
Console.WriteLine(worksheet.Title.Text)
Next
End If
Next
End If
Next