Access Form Textbox as Input query to ODBC source returns empty dataset - sql

I have an Access 2010 utility that is designed to query an Oracle DB via ODBC connection as Linked Tables. I created a simple form with two textbox's and a command button. The command button launches VBA code "DoCmd.OpenReport".
The report query Where clause looks like this:
WHERE (((PRODLAW_ITEMLOC.LOCATION)=[Forms]![frm_Qry_ByItem&Loc]![txtLocation]) AND ((PRODLAW_ITEMMAST.ITEM)=[Forms]![frm_Qry_ByItem&Loc]![txtItem]));
the values of txtItem and txtLocation are the user supplied values from the form.
This returns an empty dataset as it is now. If I query a local table, (using a single ODBC query to extract all possible values into a single local table) this method works without any issue other than the 8-10 minutes it takes to refresh the local table. If I replace the query criteria "[Forms]![frm_Qry_ByItem&Loc]![txtItem]" with a simple direct value like "1234" (assuming 1234 is a valid item number), it works without issue.
I've tried to explicitly convert the value of the textbox like "Cstr([Forms]![frm_Qry_ByItem&Loc]![txtItem])" but it made no difference. As this is a query, I can't simply create a breakpoint and examine the properties of the variables so I'm left scratching my head. I've spent hours searching SO and other sites for clues but found nothing related.
Please advise. Thanks!
mfc

Related

Excel - Off Page Reference to Microsoft Query

I am utilizing Microsoft Query in Excel to tap into an ERP table structure like Crystal would do.
In writing the SQL, is there a way to have a filter pulled from the active Excel worksheet that is embedded in the SQL instead of prompting and editing the query?
My main problem is a Like [Prompt]% in the Excel GUI for the users to change like order numbers.
Is it possible to do an off page reference from MS Query to Excel?
If by "Microsoft Query", you're talking about the window that looks like it was coded for Windows 95, stop using it. This is provided for retro-compatibility.
Anyway, if you've displayed the criteria bar in MS query, you can type a name between brackets e.g. [Something] and MS query will prompt you to fill a value.
Not what you want yet but getting close. When you return to Excel and refresh the query, the prompt will now offer you the possibility to use a cell instead of a value you need to type every type.
In the more modern connection utility accessible via menu data > Connections (+ available even if you created your table via MS Query btw), you can achieve that by using question marks in the WHERE clause.
For instance, instead of SomeField = 'SomeValue', write SomeField = ?
Then, click on the Parameters button and you'll see all the parameters you've set, each of them can be attached to a cell's value.

How to query access table with a subdatasheet that requires parameters

I have been tasked with creating a method to copy the contents of an entire database to a central database. There are a number of source databases, all in Access. I've managed to copy the majority of the tables properly, 1:1. I'm using VBScript and ADO to copy the data. It actually works surprisingly well, considering that it's Access.
However
I have 3 tables that include subdatasheets (to those that don't know, a subdatasheet is a visual representation of a 1 to many relationship. You can see related records in another table inside the main table). When My script runs, I get an error. "No value given for one or more required parameters." When I open Access and try to run the same query that I've written in SQL, It pops up message boxes asking for parameters.
If I use the query wizard inside Access to build the select query, no parameters are required and I get no subdatasheet in the result set.
My question is this: how do I write a vanilla SQL query in my VBScript that does not require parameters and just gives me the data that I want?
I've tried copying the SQL from Access and running it through my VBScript and that doesn't seem to do the trick.
Any help is greatly appreciated!
As it turns out, you need to make sure that you've spelled all of the field names properly in your source query. If you've included additional fields that aren't actually in the source or destination table they'll need to be removed too.

Update multiple records in SQL from Access without error "The data has been changed"

I am working with an ODBC connection between Access 2013 front end and a SQL Server 2008R2 back end. I have both “Datasheet” and “Continuous” forms that display multiple records which are sorted on an “order” field (integer).
The record source of these forms is a query (an Access local query right now, but I don’t think that switching it to a SQL Server view will solve my problem). Users use these forms to set/update the order of their records for reporting purposes.
My problem: the forms are updateable, but keep throwing the error
The data has been changed. Re-edit the record.
I know this error can be solved by setting the respective form to re-query after every update, but that is equally frustrating to the user because then their records are constantly re-sorting on them as they are trying to set the order (and the form "blips" after every entry).
(I have the field "Timestamp" in all my tables. I know a similar error is raised if one does not have this field in a SQL BE database linked to an Access FE.)
What is the best way to allow the users to update the order of all their records without the form resorting on them? (I would like to keep the “sort” in the query on the “order” field so when they open the form next time it displays the records in the order they specified.) I’ve read about using unbound forms with a stored procedure to update the SQL data, but this seems to be useful for one record at a time. Could I use a temp local table, and then do a batch update with a stored procedure? If that is the best answer, I also ask for some example code to get me headed in the right direction. :)
A simple answer! Add Me.Refresh to the AfterUpdate event on the form or subform. Then when a user does want to update the form based on their new order, they can click a "refresh" button that is set to Me.Requery or Me.Parent.Requery depending on the form or subform, respectively.

Change select statement in SQL from Excel - end user

I have a decent size SQL statement that I have connected to an Excel worksheet and it runs fine. The question I have is would it be possible to have the end user enter a list of values in an excel sheet or somewhere else and have those values added to a WHERE clause in my SQL to limit the results per the users needs without the user having to go into connection and alter the SQL etc.? Thank you.
Yes. I do it as part of a VB script. I'm not a VB expert and I didn't set it up- I just know enough to tweak some changes that the users require.
Conceptually- provide an area in th Excel template for users to enter the parameters, use VB to get the values of those parameters, then pass them to the SQL statement.
You can create a Data Connection in Excel that utilizes a parameter. Whether you are calling a Stored Procedure on the DB or sending raw SQL, you can replace part of the statement with a ?. Tie that parameter to a specific cell. Now all your user needs to do is enter/change the value in that cell and it will re-query the database using that value as the parameter.
(I don't have Excel in front of me, otherwise I'd walk you through the exact steps)

New SQL table value won't stay

I am new to dealing with SQL Express DB tables. I have a Windows application that gives the user a textbox that is bound to a value in my dataset (ds) which reflects my SQL table (Specs) field. The user can change the numeric value of the textbox and I can see by setting breakpoints that it created the new value in my dataset (I used MsgBox(Ds.Specs.Rows(0).Item(10) to determine this to be true). However, when I open the application back up, the OLD value appears again in the text box. It is like my dataset is not updating the SQL server table.
Again, I am new to SQL tables and allowed the wizard to create all my insert/update/delete statements which appear to be in place. Any idea why my values won't stick?
Thanks.
Once the element is put in there has to be a database submitChanges() function that has to be called to actually store your new information Im not sure exactly what the command is in VB but in c# its OnItemSubmitt(). Its all .NET so the command should be the same.
In .NET, you'll want to be sure to call the function AcceptChanges() on the Dataset object. This saves information that has changed since it was loaded or since the last time AcceptChanges() was called.
Some information can be found here on the function, and an example of its use.