Adding 2 bits of code together

Richard66

Richard
Local time
Today, 17:06
Joined
Aug 20, 2009
Messages
55
Hi
I have the following code on a form which runs on the on close event and compacts the database when it reaches a certain size. (which is in a module). But I would like to add the second piece of code to the button as well to disable the shift key. How do I run these to bits of code together? Sorry I am not very experienced with VBA.
Thanks Richard:confused:
Code 1
Private Sub closeFrmswitchlogin_Click()
On Error GoTo Err_closeFrmswitchlogin_Click
MsgBox "Access will compact the database if a certain size is reached, so please wait untill the process finishes.", vbInformation, "Please Read!"
CompactCurrentFile
DoCmd.Quit
Exit_closeFrmswitchlogin_Click:
Exit Sub
Err_closeFrmswitchlogin_Click:
MsgBox err.Description
Resume Exit_closeFrmswitchlogin_Click
End Sub

Code 2
Private Sub Command23_Click()
'This code disables shift key'
Dim db As Database
Dim prop As DAO.Property
Set db = CurrentDb
Set prp = db.CreateProperty("allowbypasskey", dbBoolean, False)
db.Properties.Append prp
End Sub
 
You just need to add the code within code to to the onclose event like this:

Private Sub closeFrmswitchlogin_Click()
On Error GoTo Err_closeFrmswitchlogin_Click


Dim db As Database
Dim prop As DAO.Property
Set db = CurrentDb
Set prp = db.CreateProperty("allowbypasskey", dbBoolean, False)
db.Properties.Append prp


MsgBox "Access will compact the database if a certain size is reached, so please wait untill the process finishes.", vbInformation, "Please Read!"
CompactCurrentFile
DoCmd.Quit
Exit_closeFrmswitchlogin_Click:
Exit Sub
Err_closeFrmswitchlogin_Click:
MsgBox err.Description
Resume Exit_closeFrmswitchlogin_Click
End Sub
 
Thank you so much for replying back to me.
Thats great i will do it like that then. It makes perfect sense now!!
thanks again
Richard
 

Users who are viewing this thread

Back
Top Bottom