Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check DB attribute before Form_Load in order to display msg box.

Status
Not open for further replies.

bcw8

MIS
Sep 7, 2005
5
US
I would like to display a message when the form loads, it will warn the user that they are in update mode if the db attribute is not set to read only. I have the following: however it is not displaying the msgbox. Can someone point me in the right direction.

Private Sub Form_Load()
vAttributes = GetAttr("C:\TM.mdb")
If vAttributes = vbEdit Then
MsgBox "Database is in Update Mode!", vbInformation, "UPDATE MODE!"
End If
End Sub
 
Function CheckFilesAtt(FilePath as String)
On Error GoTo ErrorHandler
Dim Fso As New FileSystemObject, FilePath As String
'FilePath = CurrentDb.Name

If FilePath <> "" Then CheckFilesAtt = Fso.GetFile(FilePath).Attributes
ErrorExit:
Exit Function
ErrorHandler:
MsgBox Err.Description
Resume ErrorExit
End Function

Note that in refrences you must make a ref to micarsoft scripting runtime to use the above.

Herman
Say no to macros
 
Hi
Would the .Updatable property be more suitable?
 
Hermanlaksko,

I'm that skilled in VB so I'm not sure how to implement the code that you have provided. Can you please provide further directions?
 
Sure. :)
1. Add the above into any module.
2. In modules goto Tools/refrences.
3. Find "Microsoft scripting runtime" and chk this.

To call the function try this:
Sub Test()
Dim FileAtt
FileAtt=CheckFilesAtt(CurrentDb.Name)
end sub

Tab thru the sub using the F8 key.
You can add the above sub into the same module as the functio if you like.

Herman
Say no to macros
 
Well your Q has led me to look into this, and there are several ways to do this. And here is a simple one !

FilePath = GetAttr(YrFilePathAndFileName)
'ie.(CurrentDb.Name)
Paste this into any code. No references etc. are needed!

vbNormal 0 Normal.
vbReadOnly 1 Read-only.
vbHidden 2 Hidden.
vbSystem 4 System file.
vbDirectory 16 Directory or folder.
vbArchive 32 File has changed since last backup.
vbAlias 64 Specified file name is an alias. Available only on the Macintosh.

Look in access help ;-)


Herman
Say no to macros
 
bcw8 Just to make sure, you are talking about the file's attribute, not about opening the database as read only?
 
I am only using the currentdb.name as an example, the GetAttr(YrFilePathAndFileName)
will work with any variable filename you sick into YrFilePathAndFileName


Herman
Say no to macros
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top