Click to See Complete Forum and Search --> : Can any body Help me !!! Creating Triggers in VB 6.0


January 2nd, 2000, 11:38 AM
I need to create trigger on a table which should fire when any of the column is modified. I am using Visual Basic 6.0 as IDE and Access 8.0 as my database. MSDN online speaks about creating triggers but I am not aware how and where to create the triggers, I mean code window. Can someone helm me and tell me in detail how do I create triggers in VB using Data View Window or any other way.

Thanks
Gibli
:-)

Lothar Haensler
January 3rd, 2000, 02:11 AM
AFAIK triggers are a SQLServer "thing" only.
thus, you need a client that can communicate to SQL Server. I suggest you use ISQL/w or Enterprise manager that comes with SQL server 6 and above.
To create a trigger:
CREATE TRIGGER mytrigger on yourtablename
FOR INSERT, UPDATE
AS
...write your SQLCode here

January 3rd, 2000, 07:43 AM
Thanks for the response.

I saw in MSDN library which talks about creating triggers in VB 6 for the Access database, they have shown the e.g. of NWIND.mdb. But the MSDN doesn't tell me where exactly I have to code this trigger. MSDN says you have to open Data View WIndow
Database
Tables
Right click on the table you want to create a trigger but I didn't see any option available for me to create a trigger.


Can anybody help me!!! The company where I am working presently is using MS-Access 8.0 as back-end amd VB6 as front-end. I can't use SQL server 6.0. I know that triggers can be implemented easily in SQL server 6 and oracle. But I am not aware how to implement triggers. I need the following feature :

Whenever a user tries to update TABLE A, a record should be inserted in TABLE B
which will tell me me what field in the TABLE A has be changed. How can I implement this functionality using VB6 and Access Database. I would appreciate it if somebody can explain it with an example.

Thanks,
Sri

Gary Grant
January 3rd, 2000, 11:03 AM
Triggers are not available in Access. You may be able to emulate triggers partially by using cascading updates/deletes. The rest has to be done inside your program with code and transactions.

Lonely Wolf
January 3rd, 2000, 11:10 AM
I think you can create a sub/function that writes records in table B, you can call this sub/function passing records changed everytime you code the update.
I tried this to create a log file in access database, every operation calls a function that saves in a table the operation done. I'm sorry but i cant' write code now.


private sub updatebutton_click()
.
.
.
' here the code to update
.
.
trigger (records_changed)
end sub
.
.
.
.
public sub trigger(records_changed as ....)
.
.
.
'here the code to write data in table B
.
.
.

end sub

January 3rd, 2000, 04:09 PM
How will we know which field has been modified before updating? Is there any good solution for my problem. Can anybody put me in the right direction? I appreciate you people are trying to help. Give me example please!!!!!

Thanks,
Sri

Lonely Wolf
January 4th, 2000, 05:22 AM
You can put a string equal to"" at beginning and everytime a textbox associated to a field changes it can set the string to a value, a.e.:


private sub text1_change()
'here you can also add code to test if already
'changed, something like the function instr to
'serach if mystring has 1

mystring = mystring & "1"

'it says the first field was changed so need
'to be updated
end sub




In the update button you search in mystring what fields are changed.

gibli
January 4th, 2000, 06:51 AM
I will try it out.

Thanks,
Gibli

January 5th, 2000, 09:04 PM
Thank you guy Lonely Wolf :) U have been very helpful.

- Gibli