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

SQL works in Query window but not in VB

14
Hi,

I am executing sql from VB to populate a form... (I'm building a search, so my code takes what the user inputs, queries the database, and then populates a table, to which the fields on my form are tied.)

The query runs fine (compiles and runs without throwing any errors). I can see in my "watch" in the debugger that the variable has the correct query text. But, when I open a new recordset with the query, I get no records.

To be sure it wasn't the sql, I copied my query into a query (sql view) and it executes just fine - 35 records.

the command is what you would expect:
Expand|Select|Wrap|Line Numbers
  1.  rst2.Open stSql 
where rst2 is the recordset (properly initialized, and showing up with everything correct in the watch), and stsql is the variable containing my sql query as a string. (showing up in source for rst2 in my watch, and running fine as a separate query). But no records in rst2.

I am concerned that it's something particular to my SQL syntax that won't work when passed/executed from VB:

Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM FullTable WHERE CodeA LIKE '*' & 'ABC' & '*'"
  2.  
Any thoughts??

Thanks for your help!
Sep 26 '06 #1
5 3417
PEB
1,418 Expert 1GB
Hi,
U've mentioned a form isn't it?

So rst.open YourSQL it's interesting like a construction.... I've seen it for the first time for this pupose and with recordset object in fact for the first time...

It's strange how it works.. but if you don't have a compile error so there is a functionnality like this!

I suggest you to try

Forms![YourForm].RecordSource = YourSQLString

But put this on Load form event procedure

:)
Sep 26 '06 #2
lmawler
14
Thanks for the idea!

The way I'm currently doing this is to have a search window that takes what information I want to find and then builds a query that writes the searched for records to a table that is permanently set up, but that I write and delete records in for each search.

So, I create a recordset to store the data from the query and then write it to the table that the form is tied to. This way, I don't have to target the individual fields.

Your command you provide seems like it will tie the whole form to the recordset. Is that true? What does that command do exactly?


>>Forms![YourForm].RecordSource = YourSQLString

I have actually tested putting in a simpler SQL string into the stSql, and it works just fine (inside rst.Open stSql). So, I think it's the syntax of the SQL string... which works in the query window, but not when passed this way.

Is it a function of using rst.Open? Would it work if I put the same SQL statement into Forms![yourForm].RecordSource = YourSQLString? Or is this an issue with my syntax conflicting with VB?

Thanks!
Lea Ann
Sep 26 '06 #3
lmawler
14
I see. Since my query has the same fields as the table my fields are tied to, the command just overrides the original table I was tied to?

However it works, it does!

Thanks!!
Lea Ann
Sep 26 '06 #4
lmawler
14
Hi again,

If I need to put data from the form recordsource into a field, how would i do that?

I had my fields on the form tied to the search table I referred to, but if I typed in the field, it was modifying my original table. So I unbound them, but I don't know how to refer to the recordsource data to target the unbound fields.

Thoughts?

thanks,
Lea Ann
Sep 27 '06 #5
PEB
1,418 Expert 1GB
It seems strange...

In the same time U want that the field is bound and Unbound???

When a field is bound - the data appears in the respective field and when it's modified so it's also modified in the source object!

Obviously you need only to visualize the information without modifications...

So in your form you can activate the property Allow Edits As False!

:)
Sep 30 '06 #6

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

Similar topics

2
by: M.L. | last post by:
Hi. I visit a favorite real estate web site using IE6 but can't get a js function on it to work at home. It works fine on the job. At home I placed the site into my Trusted Zone and allow or prompt...
5
by: ms | last post by:
Why does this select query return the correct records but when I make it a delete query I get a msgbox with "Could not delete from specified tables". SELECT BMIDLog.* FROM stageBMIDLog INNER...
5
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
8
by: johnsonholding | last post by:
Here is the code for a pop-up window that works in Firefox and not in IE - I get a java error or something, Here is the code : </script> <SCRIPT language="JavaScript"...
4
by: spamsickle | last post by:
I've created a query using the Query Designer under VB Express, and I can execute it in the Query Designer to verify that it returns the data I want. My database is called Area. It contains one...
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
2
by: splever | last post by:
I have a update query which updates correctly in the query window, but not when executed in vba. The VBA is ====================================================== strSQL = "UPDATE " & _...
12
by: zwasdl | last post by:
Hi, I'm using MS Access to query against Oracle DB via ODBC. Is it possible to use HINT in Access? Thanks, Wei
2
by: pmacdiddie | last post by:
I have this sql that comes from the debug screen... where it fails in code. 'First' is not a recognized function name. I had this running on another machine where it did not question the...
3
by: vljones | last post by:
I am either having an extended blond moment or have been looking at this too long. This is a basic question but I simply cannot get my head around the solution. I have a Search form with grouped...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.