473,408 Members | 2,839 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,408 software developers and data experts.

Access command button to invoke a trigger in SQL can it be done

I have a form called allpayments that allows for data entry to a table called CUST_PAYMENTS. On the form I only have certain fields from the table. PAT_ID, TRNSDT, TRNSCD, AMNT. now in SQl I have a trigger called add_to_total2.

The trigger on insert adds the AMNT to the total payment in another table. My issue is when the users enter data into the table. It is being uploaded to the SQl tables via the ODBC connection, but it is not triggering the trigger. So I need to write a code on a command button on the form that will invoke the trigger in SQL to run. any help.
May 17 '10 #1
7 2168
vb5prgrmr
305 Expert 100+
Sounds to me like you don't have the trigger configured correctly... What you will need to do is to configure this trigger correctly and the best place to do that is in a SQL Forum. There is one at tek-tips.com and a few others around and they should be able to help you configure your trigger correctly...



Good Luck
May 17 '10 #2
@vb5prgrmr
I put it hear because my SQL trigger is working after a manual insert on the SQl server. What is not working is that the Access Form data entry is not viewed as an insert by SQL so it is not hitting my trigger. I need to find some code that I can put behind a command button to hit my SQL trigger
May 17 '10 #3
Jim Doherty
897 Expert 512MB
@bherring
Use a stored procedure to insert your record and pass a parameter to it
May 17 '10 #4
Ok TABLES ARE VISITS and CUST_PAYMENTS

Fields are PAT_ID which is in both tables Total payments in the visit table

AMNT, TRNSCD, TRNSDT are in the CUST_PAYMENT table. the users will enter the patient ID the amount of the payment the trasnction cod and transaction date to the form in access. once a row has been added to the CUST_PAYMENT table I need the amount of that row to be added to the total payment field of the visit table where the PATID = the patient id in the cust_payment file. I had created a triger in SQL after insert update the visit table, but when the users enter data on the form SQL is not seeing it as an insert so the trigger is not being activated. can I create and insert query in access that will take the vaules of the form and insert them into the CUTS_PAYMENT table so that the trigger can be activated.?
May 17 '10 #5
Jim Doherty
897 Expert 512MB
@bherring
bherring

I do not see why you need a trigger to be frank! the ODBC driver is not tuning into the trigger and my inclination would be to dump the trigger entirely in favour of methods that existed prior to the invention of those things - for which I am not a great fan myself.

Wherever possible I personally favour keeping processing on the server and stored procedures are all about keeping the processing precompiled and optimised on the server.

The idea is that you place your sequence code CRUD (create, read,update,delete) in nice tidy little packages in stored procedures and make calls to them to do the work server side, as opposed to on the client. You are doing a mixture of both and many would argue that the simplest way is to just to fire off an update SQL statement in the 'afterupdate' event of textbox control servicing your AMNT form control and let it deal with the foreign table value accordingly and thats it!... job done!... not a trigger in sight and no complicated stored procedures either!

But given the client is not 'SQLing' properly and given you 'have' that trigger all you want to do is get it activated! that is the thrust of the thread, so that is why I mention a stored procedure. You are obviously working server side so this is my little contribution to your understanding as to what else there is out there 'other' than triggers.

If a stored procedure was to do the work then it obviously does it server side. This would activate the trigger because both routines are sitting on the same machine. In order to make the stored procedure do something meaningful in these circumstance you would have to pass/provide 'something' to it, to enable it to its work... and that is a parameter value.

Below is a stored procedure that takes a single parameter of the datatype INT namely your PATID value it then uses that value to UPDATE the AMNT amount in the PAT_VISIT table on the server, but only where the Patient ID field matches the PATID field in the CUST_PAYMENT table.

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.usp_Update_Pat_Visit_Amount
  2. (@PATID int)
  3.  
  4. AS
  5. UPDATE PAT_VISIT
  6. SET PAT_VISIT.[Total Payments]=CUST_PAYMENT.amnt
  7. FROM PAT_VISIT, CUST_PAYMENT
  8. WHERE CUST_PAYMENT.[PatID]=@PATID
  9. GO
So how do you get this procedure working? heres how, firstly you create it on the server. If you created the trigger you can create this as well, just paste it into a new procedure window.

Now that it is created and you have set the relevant permissions on the server to use it, you want to call it from your frontend application. The easiet way to call it is to create a simple 'passthrough' query and save it.

The passthrough query is a conventional query having an SQL property. It is that SQL property text string that we can manipulate whereby we 'pass' a parameter to it replacing the @PATID section of the string with a value in code.

So.. next step....create that passthrough query and in the SQL window just paste this into it and save it as qryPassthrough and then paste the following into its SQL window save and close the query

dbo.usp_Update_Pat_Visit_Amount @PatID

Now you can place the following code wherever you wish either on a command button to test it out and then maybe later on the afterupdate event of your AMNT textbox

Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim qdf As DAO.QueryDef
  3. Set db = CurrentDb
  4. With db
  5.      Set qdf = .QueryDefs("qryPassthrough")
  6.      qdf.SQL = "dbo.usp_Update_Pat_Visit_Amount '" & Me!txtPATID & "'"
  7.      .Close
  8. End With
  9. 'turn warnings off and run the passthrough
  10.     DoCmd.SetWarnings False
  11.     DoCmd.OpenQuery "qryPassthrough", acNormal, acEdit
  12.     DoCmd.SetWarnings True
Now the point of all of this is to show you that the stored procedure is actually updating that value for you and NOT the trigger so there really is not point keeping that trigger at all from how I understand this.

Bit long winded this post to say the least, but I hope I am helping you a little as to what is available to you :-)
May 18 '10 #6
Thnak you Jim for your work on this. Your explanation makes more sense to me.

Bypassing the trigger and creating an update procedure by itself,but the part I was missing was the Pass through Query. I have not worked with access in many years and neither has anyone else in our group. We use Microsoft SQL servers and SQL report writers and someASP programming. I was looking for the best way to handle it and my SQL guy said a trigger and since I have never worked with a trigger before that was forieng to me.
May 18 '10 #7
Jim Doherty
897 Expert 512MB
@bherring
Glad it helped you :-).

Regards
May 18 '10 #8

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

Similar topics

2
by: Sam | last post by:
Trying to change the visible property on a command button (access97) based on a record felid on the form. The felid is a check box felid and I am trying to make the button disappear with the...
9
by: Melissa | last post by:
What is the code to delete a command button from a form? Can the code be run from the click event of the button to be deleted? Thanks! Melissa
0
by: Joachim | last post by:
I wonder if it is possible and if it is how it is done to trigger a right-click event performed on a command button in Visual C++ 6? The ClassWizard only gives two options: BN_CLICKED and...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
24
by: questionit | last post by:
Hi I am new in Ms Access I need to know how can i create a command button on a form. When it is clicked, a table is opened that is associated to the data in a field i have. E.g: if (...
3
by: gra | last post by:
Hi Access 2002 I have a Command Buton using some VB code to open an Excel spreadsheet. However, when the spreadsheet opens it doesn't refresh the data. The spreadsheet is a pivot table which...
9
by: larryimic | last post by:
I have created a Access production database that records good parts and bad parts to a table thru querys using macros and command buttons on a form. A report (part label) is printed each time a...
1
by: tymperance | last post by:
I have a 2007 database that I need to add a command button that will open a new Outlook task and allow the user to input the assignment, start date, due date, etc. I've got plenty of code scripting...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
9
by: jcnovosad | last post by:
Hello, I need the procedure and/or code to add a command button to the Main Switchboard form, so the user click it and creates a full backup of the database in other folder, where the database name...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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
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.