473,382 Members | 1,392 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,382 software developers and data experts.

Referencing form value from within a query

I'm sure this shouldn't be too difficult, but I lack familiarity with the MS object model.

Suppose I have a table "Purchase_Orders" and a form "TEMP" which I am using to look up a customer's orders. The form has a text field named LastName for typing in new orders, but first let's look at the previous orders. Elsewhere on the form is a Office Web Components Spreadsheet version 11.0, which will run a query and show the result list.

The Spreadsheet object connects to the data source, and the test connection checks out good. The query :

SELECT * FROM Purchase_Orders WHERE
(Purchase_Orders.LastName=Forms!TEMP!LastName)

The result returned is:

No value given for one or more required parameters.

This seems to be a matter of syntax and not referencing the form field properly from inside the query. If I instead use

WHERE LastName='Smith'

it works just fine.

Can someone help me out with the proper MS object referencing convention?
Jun 18 '07 #1
11 3486
Rabbit
12,516 Expert Mod 8TB
I'm sure this shouldn't be too difficult, but I lack familiarity with the MS object model.

Suppose I have a table "Purchase_Orders" and a form "TEMP" which I am using to look up a customer's orders. The form has a text field named LastName for typing in new orders, but first let's look at the previous orders. Elsewhere on the form is a Office Web Components Spreadsheet version 11.0, which will run a query and show the result list.

The Spreadsheet object connects to the data source, and the test connection checks out good. The query :

SELECT * FROM Purchase_Orders WHERE
(Purchase_Orders.LastName=Forms!TEMP!LastName)

The result returned is:

No value given for one or more required parameters.

This seems to be a matter of syntax and not referencing the form field properly from inside the query. If I instead use

WHERE LastName='Smith'

it works just fine.

Can someone help me out with the proper MS object referencing convention?
1) Is the form open when you try to run the query?

2) Is the name, not the control source or the name of the field, of the textbox actually LastName? The Name of a control and the Control Source / Field Name are different things.
Jun 18 '07 #2
puppydogbuddy
1,923 Expert 1GB
I'm sure this shouldn't be too difficult, but I lack familiarity with the MS object model.

Suppose I have a table "Purchase_Orders" and a form "TEMP" which I am using to look up a customer's orders. The form has a text field named LastName for typing in new orders, but first let's look at the previous orders. Elsewhere on the form is a Office Web Components Spreadsheet version 11.0, which will run a query and show the result list.

The Spreadsheet object connects to the data source, and the test connection checks out good. The query :

SELECT * FROM Purchase_Orders WHERE
(Purchase_Orders.LastName=Forms!TEMP!LastName)

The result returned is:

No value given for one or more required parameters.

This seems to be a matter of syntax and not referencing the form field properly from inside the query. If I instead use

WHERE LastName='Smith'

it works just fine.

Can someone help me out with the proper MS object referencing convention?
LastName is entered as a text string on the form. The syntax that identifes it is as follows:

SELECT * FROM Purchase_Orders WHERE
("Purchase_Orders.LastName= '" & Forms!TEMP!LastName & "'")
Jun 18 '07 #3
Rabbit
12,516 Expert Mod 8TB
LastName is entered as a text string on the form. The syntax that identifes it is as follows:

SELECT * FROM Purchase_Orders WHERE
("Purchase_Orders.LastName= '" & Forms!TEMP!LastName & "'")
This is only if he's trying to do it through VBA code. You don't need the quotes if you're doing from the query builder.
Jun 18 '07 #4
puppydogbuddy
1,923 Expert 1GB
This is only if he's trying to do it through VBA code. You don't need the quotes if you're doing from the query builder.

Rabbit,
That is correct. I assumed that he was running his Select statement from VBA because he didn't mention anything about the query grid, nor did he refer to the query by name like he would if it were a saved query.
Jun 19 '07 #5
Thank you all for your responses. I looked at the areas you suggested and while this surely has me on the right track, my form still needs some work:

- First I verified that the field name was correct; it is "LastName", same as the table column.

- The text field and the spreadsheet object are both part of the same form.

- Then I tried the statement:

WHERE ("My_Table.LastName= '" & Forms!TEMP!LastName & "'")

Unfortunately that didn't work either, same error message given.

I am building this query by right-clicking on the spreadsheet (in Design view of the form), then selecting Microsoft Office Spreadsheet 11.0 Object > Commands and Options

This yields a dialog box with tabs, and under the Data Source tab putting in the connection string and "Command Text or SQL".

Again, if I specify the WHERE clause with "WHERE LastName='Smith'" it will return an appropriate list of results.

Just for spite I tried putting in

MsgBox "Whatever"

just to see what it would do and it throws:

Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

...Any suggestions what I might try next?

Tim
Jun 19 '07 #6
puppydogbuddy
1,923 Expert 1GB
Thank you all for your responses. I looked at the areas you suggested and while this surely has me on the right track, my form still needs some work:

- First I verified that the field name was correct; it is "LastName", same as the table column.

- The text field and the spreadsheet object are both part of the same form.

- Then I tried the statement:

WHERE ("My_Table.LastName= '" & Forms!TEMP!LastName & "'")

Unfortunately that didn't work either, same error message given.

I am building this query by right-clicking on the spreadsheet (in Design view of the form), then selecting Microsoft Office Spreadsheet 11.0 Object > Commands and Options

This yields a dialog box with tabs, and under the Data Source tab putting in the connection string and "Command Text or SQL".

Again, if I specify the WHERE clause with "WHERE LastName='Smith'" it will return an appropriate list of results.

Just for spite I tried putting in

MsgBox "Whatever"

just to see what it would do and it throws:

Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

...Any suggestions what I might try next?

Tim

Maybe the cryptic message was saying that the return value was a null. Also maybe the Excel object prefers the dot operator over the bang (!) operator. Try these different variations in syntax and see what happens.

WHERE ("My_Table.LastName= Forms!TEMP!LastName”)

WHERE ("My_Table.LastName= '" & nz(Forms!TEMP!LastName & "'"),””)

WHERE ("My_Table.LastName= '" & nz(Me!LastName & "'"),””)

WHERE ("My_Table.LastName= '" & nz(Me.LastName & "'"),””)
Jun 19 '07 #7
Rabbit
12,516 Expert Mod 8TB
Try this:
SELECT * FROM Purchase_Orders WHERE
(Purchase_Orders.LastName=Forms!TEMP!LastName)
Jun 19 '07 #8
Just to give you some perspective, what I found was that all these ideas were good but none of them worked in the Spreadsheet object, most likely because the ActiveX control does not fully implement the VBA conventions.

If I opened a datasheet and had a form open at the same time, then yes the syntax was correct for reading the form control and modifying the SQL query based on that. Wroked beautifully in fact.

It would seem that the Spreadsheet ActiveX object just has limited functionality.

After many, many hours of trial and error :-) I have changed my approach and now am using a subform that has a table merged to my original form field. This gives me pretty much the functionality I wanted, of being able to see rows existing in the table as I add a new row using the form.

Again, thanks for your efforts.

Tim
Jun 19 '07 #9
Rabbit
12,516 Expert Mod 8TB
Just to give you some perspective, what I found was that all these ideas were good but none of them worked in the Spreadsheet object, most likely because the ActiveX control does not fully implement the VBA conventions.

If I opened a datasheet and had a form open at the same time, then yes the syntax was correct for reading the form control and modifying the SQL query based on that. Wroked beautifully in fact.

It would seem that the Spreadsheet ActiveX object just has limited functionality.

After many, many hours of trial and error :-) I have changed my approach and now am using a subform that has a table merged to my original form field. This gives me pretty much the functionality I wanted, of being able to see rows existing in the table as I add a new row using the form.

Again, thanks for your efforts.

Tim
Glad you found your solution.

Am I hearing you correctly though that you didn't have the form loaded before opening the spreadsheet? An unloaded form has no values.
Jun 20 '07 #10
Nope, the form was loaded all right :-) The text fields were on the top part of the form, and the spreadsheet object was in the bottom part.

It started working once I deleted the spreadsheet and replaced it with a sub-form containing a table. The table is linked to the form field.

Interestingly, I found if I had done a separate table generated by a query, suddenly the format

WHERE MyTable.LastName = [Forms]![MyForm]![LastName]

Becomes valid, even though it didn't work in the Spreadsheet query.

...Go figure! :-)
Jun 21 '07 #11
Rabbit
12,516 Expert Mod 8TB
I think it's most likely a case of scope. The spreadsheet object is in a world itself and doesn't have access to the values of the forms. Althought I suppose you could change the value of the spreadsheet from a form rather than from in the spreadsheet.
Jun 21 '07 #12

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

Similar topics

2
by: sreddy | last post by:
I am trying to write a sql query on self referencing table. Just to brief ..Database is related to a Hiring department of the Qwest company. I need to generate a Report used by in HR...
10
by: Data Guy | last post by:
In my approach to validation for widgets, i write javascript functions. At the end of the document, inside the form, i invoke the function as <FORM NAME="testit"> <INPUT TYPE="TEXT" VALUE="2"...
1
by: Tyson | last post by:
Hi Very novice sorry. Trying to add a simple query to a textbox...I am getting Enter Parameter Value I have a Form called (frm_tbl_RR_Datacapture). With a series of Textboxes. I am wanting...
2
by: Rooksarii | last post by:
Hello folks, Let me first apologize for any impropper terminology I may use as I am presently trying to broaden my Office knowledge by diving into Access head on. My specific problem is this....
17
by: Paul Helmuth | last post by:
All, (here's an easy one)... This is probably a stupid question - please bare with me as I am new to dotNet. How does one reference objects on a form from a module? In 6.0 you could simply...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
2
by: Elliot Rodriguez | last post by:
I have a form that contains a mix of dynamic controls and declared controls. All of them are intrinsic .NET controls. Several functions within the page use Request.Form to query the value of the...
2
by: Axel | last post by:
Hi, a question about something that seems very simple at first glance: is it possible to reference other controls of a subform in a query window without referencing through the parent form? I...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.