Link to home
Start Free TrialLog in
Avatar of quentin2
quentin2

asked on

Block a Key during the execution of a program

Hi!

I am writting a piece of code that updates my databases
when i put a txt file in a certain folder.
The presence of a new file triggers a code that reads the file, update the DB and put the file in an Archive folder.

On the other hand i use a client access to the program.
I access the DB very frequently.

My problem: it happens that i get records containing old records in some fields and new ones in other fields because the system is updating in the background my DB.

The solution seeked:I need to be able to block the refresh screen = F5 when the DB is being updated.

Is there a simple piece of code that can lock refresh and ulock it moments later?

I will definitly grade the best answer!
Thanks
Avatar of AndrewDev
AndrewDev

What database are you using? Most databases have record locking or snapshot capability which prevents inconsistant data being read. It is one of the basics of data integrity in a database. Locks are set by the writing program and clients use the lock information to determine what to display.

Regards
Andrew
Avatar of quentin2

ASKER

Andrew,

Hum i am using Oracle,
but this is not the problem here really.

Because i just need that during the VB execution of the program which flows data into tables that the F5 key becomes unusable
 
like, Where does the user presses F5 to refresh?
Not exactly what you want but:
You could set a flag in the database to indicate update in progress and then check that flag before reading the data in your client. If the flag is set either delay or cancel the read.

Be sure to clear the flag on completion of the update and if the writing program encounters any error.

I have searched MSDN for disabling F5 and refresh but without any luck. So this is the best I can come up with.

Regards
Andrew

Oops i know understand the i did defined the problem properly..

Euuuh the user is accessing the Datas through a program that access the DB.
The program is the one my company owns.
It is a Trading software program

Quentin
like, Where does the user presses F5 to refresh?
sorry for the repost.

The system which is updating your DB, could use transactions, so that either your new changes will only be reflected in Refresh, or your old changes alone will be reflected. Not a mixed one.
Is your Trading Software program, a VB source, or a 3rd party one?
Unfortunately it does not

My system access an Active X dll, this piece of software updates the DB.
In the meantime it is still possible to refresh the screen and acces the DB that are being updated.
There is no possibility to disable the F5 button within the software and i am hoping to be able to make it from the dll.

Quentin
>Unfortunately it does not

it does not what? it does not use transactions or does not refresh properly?

In that case are u using transactions in your activex dll, when updating the data?

cheers.
it does not use transactions.
(what are transactions anyway??)

The active x is just writting to the DB and performing a few calculations

cheers
q
ok, a transaction is a set of changes made to a database's data.

you could mark the beginning of a transaction with the BeginTrans statement, commit or save the transaction using the CommitTrans statement, or undo all your changes since BeginTrans by using the RollbackTrans statement.

thus before you start your updations to database you could issue a Begintrans statement, and finally issue a CommitTrans statement.

if some error occurs inbetween, optionally, you could reverse all changes by a RollBack statement.

this is supported in both ADO and DAO.
The change in usage in ADO is you should use RollbackTrans, instead of Rollback in DAO.

e.g.
Private Sub cmdUpdate_Click()
dim lTrans as boolean

On Error GoTo ErrHandle
lTrans = True
Conn1.BeginTrans
:
'your sql statements here
:
Conn1.CommitTrans
lTrans = False
exit sub

ErrHandle:
msgbox "Could not update. Error:" & err.number & " " & Err.description & " Source: " & Err.Source
If lTrans Then
  Conn1.RollbackTrans
  lTrans = False
End If
End Sub

hope this helps.
cheers.


Thank you.

but i just need to freeze the F5 usage for the time my active X is being processed.

        It means i am searching for a piece
        of code which freeze the usage of the
        key, and then a piece of code to unfreeze
        it
                      OR
        something else that can fit within the
        activex  and freeze the F5


Quentin
Avatar of glass_cookie
Hi!

How about hiding the whole thig until all the processing is done, then show the form again...

OR

You could set the 'Enabled' property to the form to False (activities can still be carried out at the background) then Enable the form again.

That's it!

glass cookie : )

There are thousands of way to turn around i suppose...
Thanks

But i am stille searching for a way to disable F5 from a VB program.

Quentin
Hi!

Does this work?

Download...
http://www.vb-helper.com/Howto/lowlevelkey.zip
Disable certain key combinations such as ALT-TAB (5K)
ASKER CERTIFIED SOLUTION
Avatar of glass_cookie
glass_cookie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
http://www.planetsourcecode.com/upload/ftp/Keyboard%20L2014952720.zip

     This is an updated program to my previous Keyboard Lock. It now can Lock at a certain time of day, unlockat a certain time of day, lock if the computer is Idle for x amout of minutes, and it disables your computers bootkeys. It is lightly commented. Please send comments or suggestions. Enjoy!-Sorry about uploading the wrong zip.-Fixed
 
thx i'll have a look

Quentin
Hi quentin2@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept glass_cookie's comment(s) as an answer.

quentin2@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Comment from expert accepted as answer

Computer101
E-E Moderator