473,725 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting a value from an Access form into a SQL pass through query

94 New Member
I am creating a small Access db which performs a series of updates to a SQL database.

The Access db consists of a ‘Main Form’, from which the user can run each update via a series of command buttons.

Each update has been written as a SQL pass-through query.

Example Update:
UPDATE unit_instance_o ccurrences uio
SET fes_active_plac es =
(SELECT COUNT(*) FROM registration_un its ru
WHERE ru.fes_unit_ins tance_code = uio.fes_uins_in stance_code
AND ru.uio_occurren ce_code = uio.calocc_occu rrence_code
AND ru.progress_sta tus = 'A'
AND ru.uio_occurren ce_code = 07);
Each query is dependant on a year (Eg: 07) however I want the user to determine that year from a combo box on the ‘Main Form’.

How do I best go about this?

The key thing is that i want to be able to run my pass through query from a button on the form. Before clicking the button the user must select the year. Somehow I either want to be able to insert that year as a parameter into the body of the PTQ or if necessary I can rewrite the pass-through update queries as pure Access-update queries and insert it there instead.

Have pretty much hit a wall with this so any help would be greatly appreciated!
Sep 13 '07
22 11335
FishVal
2,653 Recognized Expert Specialist
I'm a bit confused....how does that code fit into mine? Which bits do i need to replace?
  • create working pass-through query in Query builder and save it as e.g. [qrySomeQuery]
  • then place code like the following in your form module
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cmdExecuteQuery_Click()
    2.     Dim strSQL As String
    3.  
    4.     strSQL = "UPDATE unit_instance_occurrences uio " & _
    5.              "SET fes_active_places = " & _
    6.              "(SELECT COUNT(*) FROM registration_units ru " & _
    7.              "WHERE ru.fes_unit_instance_code = uio.fes_uins_instance_code " & _
    8.              "AND ru.uio_occurrence_code = uio.calocc_occurrence_code " & _
    9.              "AND ru.progress_status = 'A' " & _
    10.              "AND ru.uio_occurrence_code = " & Me!cboYear & ");"
    11.  
    12.     With CurrentDb.QueryDefs("qrySomeQuery")
    13.         .SQL = strSQL
    14.         .Execute
    15.     End With
    16. End Sub
    17.  
Sep 19 '07 #11
Lewe22
94 New Member
Thanks!

Unfortunately still finding the same error "Operation must use an updateable query". I have just started another thread at....
http://www.thescripts.com/forum/show...22#post2826022

Any help on that would be great!!
Sep 19 '07 #12
FishVal
2,653 Recognized Expert Specialist
Does the query built in query builder work? If so, post the query SQL.
Sep 19 '07 #13
Lewe22
94 New Member
Unfortunately I don't have query builder. Can you suggest somewhere to get it from?
Sep 20 '07 #14
FishVal
2,653 Recognized Expert Specialist
Unfortunately I don't have query builder. Can you suggest somewhere to get it from?
I've meant query design which is the part of all Access versions.
Sorry if have confused you.
Sep 20 '07 #15
MMcCarthy
14,534 Recognized Expert Moderator MVP
Is "unit_instance_ occurrences uio" a query or a table?
Sep 21 '07 #16
Lewe22
94 New Member
Is "unit_instance_ occurrences uio" a query or a table?
"unit_instance_ occurrences uio" is a table, as is "registration_u nits ru"
Sep 21 '07 #17
MMcCarthy
14,534 Recognized Expert Moderator MVP
"unit_instance_ occurrences uio" is a table, as is "registration_u nits ru"
I'm trying to remember general SQL syntax. In Access a tablename which included spaces would have to be enclosed with square brackets. Whats the rule in your backend. You don't mention what backend system you are using.
Sep 21 '07 #18
Lewe22
94 New Member
My latest code...
Private Sub New_Click()
On Error GoTo err_New_Click
Dim db As DAO.Database
Dim qdfPassThru As DAO.QueryDef
Set db = CurrentDb
CurrentDb.Query Defs("Active Update Query").SQL =
"UPDATE fes_unit_instan ce_occurrences uio " & _
"SET fes_active_plac es = " & _
"(SELECT COUNT(*) FROM fes_registratio n_units ru " & _
"WHERE ru.fes_unit_ins tance_code = uio.fes_uins_in stance_code " & _
"AND ru.uio_occurren ce_code = uio.calocc_occu rrence_code " & _
"AND ru.progress_sta tus = 'A' " & _
"AND ru.uio_occurren ce_code = " & Me!cboYear & ");"
CurrentDb.Query Defs("Active Update Query").Updatab le
Set qdfPassThru = db.QueryDefs("A ctive Update Query")
qdfPassThru.Exe cute ' you can leave this out if you don't want to run the query
Set qdfPassThru = Nothing
Set db = Nothing
exit_New_Click:
Exit Sub
err_New_Click:
MsgBox (Err.Descriptio n)
End Sub
"fes_unit_insta nce_occurrences " is the table name "uio" it's alias and
"fes_registrati on_units" is the table name "ru" is it's alias.
Both tables are in my access db as ODBC linked tables to a SQL server.
Also, the combo box "cboYear" is linked to another ODBC table to pick up the year.
Sep 21 '07 #19
Lewe22
94 New Member
Sorry, the line...

"CurrentDb.Quer yDefs("Active Update Query").Updatab le"

has since been removed.
Sep 21 '07 #20

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

Similar topics

7
6419
by: rickcheney | last post by:
I just changed my Access 2002 database to a SQL Server ADP project. I had a form where the user entered a value into a text box and when a command button on the form was clicked a Report was opened. The reports record source is a query. The query uses the value from the form text box to restrict the query. Table name = EggsTable one of the columns in the table is named: EggColor Form name = EggColorForm Form text box name = ColorTextBox
2
11708
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. tCetecM1CUST (SQL Table that contains the Customer Information) tAccountingDetail (SQL Table that contains the information in the form) frmAccountingEntry (Access form used to enter data) spGetCustomerInformation (Stored Procedure which returns data using...
2
30331
by: rg | last post by:
Hi all, I have query about passing a parameter from form to a query. My situation is as follows: I have a query that pulls up some data from a table, however there is a condition that must be filled in by the user. Hence when you run the query there is a "Enter Parameter Value" prompt that must be completed. A further complication is that the parameter is actually within the WHERE statement, i.e.:
15
7256
by: brettclare | last post by:
I have linked a large SQL Server table to Access, however 'only' 2,195,439 records are shown and are available to query. Can I increase the size (cache??)/number of records showing in Access? Thank you.
10
2371
by: Hank | last post by:
We have just recently migrated the data from our Access 2000 backend to Postgres. All forms and reports seem to run correctly but, in many cases, very slowly. We do not want to switch over until we can speed things up. We would like to start implementing Stored Procedures so we can do Server-Side processing. Can anyone recommend a book that would help us learn how to use sprocs or pass-through queries? I apologize if my terminology...
11
4377
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store procedure(assume there are many columns in the table). I need to insert data into two separate tables, the relation between these two tables is 1 row of data in table1 could have multiple rows in table2 related to table1, but if the data insertion into...
2
1405
by: Lewe22 | last post by:
I am creating a small Access db which performs a series of updates to a SQL db. The Access db consists of a ‘Main Form’, from which the user can run each update via a series of command buttons. Each update has been written as a SQL pass-through query. Example Update: UPDATE unit_instance_occurrences uio SET fes_active_places =
4
2563
by: sialater | last post by:
Hello, I realise there are a lot of topics related to this problem but many of what I have found has run cold or unresolved. What I have is an addressbook clone where there are groups which have members. I have this formatted in a way where the groups are in a drop down box. Once a group is selected, the two selection boxes below are refreshed with those who are members or non members of the selected group. The user has the ability to...
13
3732
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between !! And !! Not sure how to do so (should it be a query in Access or a macro) The connection would be ODBC.
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8097
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.