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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Changing DAO to ADO

Status
Not open for further replies.

MelissaKT

Technical User
Jun 22, 2004
95
US
I really need some assistance with a FAQ that I'm attempting to use in my database. The FAQ is faq181-1172 and it's about locking down your database. Unfortunately, I'm using an Access Data Project(2003 version) and it doesn't seem to like the DAO that this particular FAQ was written in. The code from the FAQ is:
Code:
Public Function StartUp()
    Dim Designer As String
    Dim Restart As Boolean
    Dim stAppName As String
    
    Designer = "yourlogonhere"
    FIND_USER
      
    If sLogon = Designer Then
        Restart = UnlockStartup
    Else
        Restart = LockStartup
    End If
        
    If Restart Then
        'Close database and re-open
        stAppName = "MSAccess.exe " & CurrentDb.Name
        Call Shell(stAppName, 1)
        DoCmd.Quit
    Else
        If sLogon <> Designer Then DoCmd.OpenForm "TitleForm"
    End If
    
End Function
-----------------------------------
Sub FIND_USER()

On Error GoTo ERR_FIND_USER

    Dim UserParam$
    Dim sChk As String
    Dim CurrentAuditor As String
    
    UserParam$ = Environ("S_USER")
    If UserParam$ = "" Then UserParam$ = Environ("USERNAME")
    sLogon = UCase$(UserParam$)

EXIT_FIND_USER:
    Exit Sub
    
ERR_FIND_USER:
    MsgBox Error$
    Resume EXIT_FIND_USER
End Sub
---------------------------------------------
Function LockStartup() As Boolean
    Dim Restart As Boolean
    
    Restart = False
    ChangeProperty "StartupShowDBWindow", dbBoolean, False, Restart
    ChangeProperty "AllowBuiltinToolbars", dbBoolean, False, Restart
    ChangeProperty "AllowFullMenus", dbBoolean, False, Restart
    ChangeProperty "AllowToolbarChanges", dbBoolean, False, Restart
    ChangeProperty "AllowBreakIntoCode", dbBoolean, False, Restart
    ChangeProperty "AllowSpecialKeys", dbBoolean, False, Restart
    ChangeProperty "AllowBypassKey", dbBoolean, False, Restart
    Application.SetOption "Show Hidden Objects", False
    LockStartup = Restart
End Function
-----------------------------------------------
Function UnlockStartup() As Boolean
    Dim Restart As Boolean
    
    Restart = False
    ChangeProperty "StartupMenuBar", dbText, "(default)", Restart
    ChangeProperty "StartupShowDBWindow", dbBoolean, True, Restart
    ChangeProperty "StartupShowStatusBar", dbBoolean, True, Restart
    ChangeProperty "AllowBuiltinToolbars", dbBoolean, True, Restart
    ChangeProperty "AllowFullMenus", dbBoolean, True, Restart
    ChangeProperty "AllowToolbarChanges", dbBoolean, True, Restart
    ChangeProperty "AllowBreakIntoCode", dbBoolean, True, Restart
    ChangeProperty "AllowSpecialKeys", dbBoolean, True, Restart
    ChangeProperty "AllowBypassKey", dbBoolean, True, Restart
    UnlockStartup = Restart
End Function
-------------------------------------------
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant, Restart As Boolean) As Integer
    Dim dbs As Database, prp As Property
    Dim CurrentPropVal As Variant
    Const conPropNotFoundError = 3270

    Set dbs = CurrentDb
    On Error GoTo Change_Err
    
    CurrentPropVal = dbs.Properties(strPropName)
    If CurrentPropVal <> varPropValue Then
        dbs.Properties(strPropName) = varPropValue
        Restart = True  'need to restart database
    End If
    ChangeProperty = True
Change_Bye:
    Exit Function

Change_Err:
    If Err = conPropNotFoundError Then  'Property not found.
        Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
        dbs.Properties.Append prp
        Resume Next
    Else
        ' Unknown error.
        ChangeProperty = False
        Resume Change_Bye
    End If
End Function
I'm having problems with the ChangeProperty function. That is where I keep getting run-time error '91'. Again, I'd like to change this over to ADO but I'm not sure how to go about it. I'd really appreciate ANY help!! Thank you in advance.
 
why not just set a reference to the Microsoft DAO 3.6 Object Library, and then change the line

Dim dbs As Database, prp As Property
to
Dim dbs As DAO.Database, prp As DAO.Property

It's easy to use DAO in newer versions of ACCESS, just set a reference to the DAO library and be sure to explicitly define your variables for Database and Recordset

dim db as DAO.Database, rst as DAO.Recordset

the rest should be okay

PaulF
 
If you just want to get rid of the error, it may be the precedence in the project library is set incorrectly.
Look at project references, highlight the DAO reference, and use the up/down arrow buttons to move it ahead of the ADO reference (if it isn't already).

I have great faith in fools; self-confidence my friends call it.
-Poe
 
I already did that. It didn't work. I'd prefer ADO anyway because that's what everything that I have is written in. Thanks.
 
Genomon,
I had answered before I got your post. I just checked and my DAO reference is above my ADO reference. Any other ideas? I didn't think that an Access Project accepted currentdb() but I could be wrong (and I'm not sure where I got that idea?).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top