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

Simple SQL not working in Access

Hello,

I've been trying to figure out simply how to use SQL in the MS Access's Visual Basic editor, and so far I've literally run into 20 unique errors over the last couple of days. Now, I've finally got a super simplified script that doesn't return any errors, but it doesn't display anything either, and I can't figure out why. Any ideas?

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Command7_Click() 
  2.  
  3. Dim db As Database
  4. Dim rs As DAO.Recordset
  5.  
  6. Set db = CurrentDb()
  7. Set rs = db.OpenRecordset("SELECT * FROM Temporary;")
  8.  
  9. rs.Close
  10. db.Close
  11. Set rs = Nothing
  12. Set db = Nothing
  13.  
  14. End Sub
  15.  

(It's linked to a form, so that when someone clicks the submit button this code is called).

Thank you!
Jul 3 '08 #1
2 1267
DrBunchman
979 Expert 512MB
The reason that this doesn't do anything is because you've created your recordset but not done anything with it like bound it to a control.

I've moved this to the MS Access Forum where I think it's more likely you'll be able to get help than the ASP Forum.

Dr B
Jul 7 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
As Dr B said, you have opened a recordset but not done anything with it. The OpenRecordset method is intended for further code processing - loop processing of individual records, transfer of the recordset to Excel, searching for matching records, and so on.

If what you want to do is to set your form's recordsource to an SQL statement in response the on-click event of your command button you don't need the DAO recordset at all. The following single line of code will do this on its own (assuming the command button is on the same form):
Expand|Select|Wrap|Line Numbers
  1. Me.Recordsource = "SELECT * FROM Temporary;"
If the form is not the same as the one on which the button is placed the same principle applies but you need to supply the full reference to the form's name. The form has to be open for this to work (you can't change the recordsource for an unopened form this way).

Expand|Select|Wrap|Line Numbers
  1. forms("yourformname").Recordsource = "SELECT * FROM Temporary;"
etc.

You can use a similar approach in a form's On Load event to set its recordsource dynamically.

-Stewart
Jul 7 '08 #3

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

Similar topics

7
by: Jeff | last post by:
ok.... i dont know why this wont work. this is going to access DB on web. var1a = Request.Form("h1") var1b = Request.Form("h2") strSQL = "UPDATE matches SET team1a = " & var1a & ", team1b = "...
5
by: calaha | last post by:
Hi all, I have been working with this since last night, and can't quite figure out why it's not working. I have a simple login box form that is set to be my startup form in my Access app (upon...
3
by: Iain Miller | last post by:
Can anybody help me with some Access 2000 code? I don't do a lot of coding in Access & so every time I come back to do something I pretty much have to relearn the syntax from scratch so this is...
33
by: hermit_crab67 | last post by:
Can someone explain to a C newbie why this doesn't work as I expect it to work? (expectations clearly outlined in the printf statement in main routine) OS: Linux 2.4.26 GCC: 2.95.4 void...
3
by: KevinD | last post by:
thank you for your helpful explanations. In my first note I forgot to mention that my simple flatfile is a text file with a newline character at the end thus I able to get an entire record . ...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
3
by: ben | last post by:
All, What I have: I have written a VB.net application that uses Access DBs and Make 100s of Excel documents from the data. What I need: I need a Simple ASP.NET Page that will basically pass...
1
by: jack | last post by:
Hi all, I am working on perl..and am using XML::Simple to parse a xml document. I've been trying to retrieve character data from tags whose occurance is recursive.. The scenario can be better...
1
by: MattNZ | last post by:
I am working in access on a program which requires me to multiply all the values in a field by each other. This is easy to replicate in excel, but I can't figure out how to do this in access. Here...
2
by: samadams_2006 | last post by:
I'm trying to get a simple VB.NET "Web Application" (not a regular application) to work with an Access Database. Seems simple enough, but I cannot seem to get it working. If anyone has a simple...
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
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.