M
mehmeh via AccessMonster.com
Phew, I'm pretty stumped on this one. Basically I am running a quick check to
see if the user has write permissions to the database (Is there a simple way
to check this?) the security is at file level rather than through access
though.
Anyway, it writes a value to [seccheck] in the table "programversion" then
looks up the value to see if it was correctly written. This is a little
overkill because it will throw an error at the time of trying to write the
value however I thought is better going through with the check anyway:
Dim stDocName As String
Dim strSQL As String
Dim stwrite As String
Dim stcompare As String
'Note: Thsi is not meant to be a foolproof way of keeping people out,
it's just to stop people accidently wandering in.
stwrite = 1 + DMax("[seccheck]", "programversion", "ID = 1")
'write the value of stwrite to where it was looked up before being
incremented
strSQL = "UPDATE programversion SET programversion.seccheck = '" &
stwrite & "' WHERE ((ID=1));"
CurrentDb.Execute strSQL
'look up the value writen
stcompare = DLookup("[seccheck]", "programversion", "ID = 1")
'Check if the write was successful.
If stwrite = stcompare Then
'allow them access
stDocName = "admin functions"
DoCmd.OpenForm stDocName, , , , , acDialog
Else
MsgBox "Sorry, you do not have the correct access permissions"
GoTo Exit_cmdadmin_Click
End If
Note: the err. also contains the above message to cover for the update
query's error.
Now, this worked when I first done it (I obviously have the correct
permissions) and has worked the odd time since however most usually it
doesn't.
After some fault finding it appears that the value writes correctly but the
dlookup drags up the old value. I'm assuming I need to refresh the table in
between? If so then that's a problem because I don't know how to (haha), I've
tried all the usual programversion.refresh, docmd requery, and currentdb.
programversion.refresh. None of the work because it can't find the table. It
is a linked table and isn't the record source of the form where the code lays.
Hellllllppppp
much appreciated.
see if the user has write permissions to the database (Is there a simple way
to check this?) the security is at file level rather than through access
though.
Anyway, it writes a value to [seccheck] in the table "programversion" then
looks up the value to see if it was correctly written. This is a little
overkill because it will throw an error at the time of trying to write the
value however I thought is better going through with the check anyway:
Dim stDocName As String
Dim strSQL As String
Dim stwrite As String
Dim stcompare As String
'Note: Thsi is not meant to be a foolproof way of keeping people out,
it's just to stop people accidently wandering in.
stwrite = 1 + DMax("[seccheck]", "programversion", "ID = 1")
'write the value of stwrite to where it was looked up before being
incremented
strSQL = "UPDATE programversion SET programversion.seccheck = '" &
stwrite & "' WHERE ((ID=1));"
CurrentDb.Execute strSQL
'look up the value writen
stcompare = DLookup("[seccheck]", "programversion", "ID = 1")
'Check if the write was successful.
If stwrite = stcompare Then
'allow them access
stDocName = "admin functions"
DoCmd.OpenForm stDocName, , , , , acDialog
Else
MsgBox "Sorry, you do not have the correct access permissions"
GoTo Exit_cmdadmin_Click
End If
Note: the err. also contains the above message to cover for the update
query's error.
Now, this worked when I first done it (I obviously have the correct
permissions) and has worked the odd time since however most usually it
doesn't.
After some fault finding it appears that the value writes correctly but the
dlookup drags up the old value. I'm assuming I need to refresh the table in
between? If so then that's a problem because I don't know how to (haha), I've
tried all the usual programversion.refresh, docmd requery, and currentdb.
programversion.refresh. None of the work because it can't find the table. It
is a linked table and isn't the record source of the form where the code lays.
Hellllllppppp
much appreciated.