Dimensioning variables

Rob.Mills

Registered User.
Local time
Today, 17:24
Joined
Aug 29, 2002
Messages
871
I'm sure this is an easy one for some of you but it has me stumped.

I've got a book on VBA that I've been recently studying the section on Creating Database Objects. The first line in the example I wanted to copy into my database is:

Dim db as Database

When I'm entering it into the sample database it gives me the option of choosing 'Database' when I'm writing that line.

But when I try to write this exact same procedure in my database it won't let me choose 'Database' when writing that line.

Any thoughts as to why??

:confused:
 
Check that you have the relevant reference library loaded. Think that it is either (for Acc2k) DAO3.6 or Access9. To check open a module and the Editor window will open and then click on Tools / References.

HTH
 
Thanks!! It was DAO 3.6 that fixed it.

For anyone else looking at this it's listed under Microsoft DAO 3.6.
 
Got another challenge Harry,

My code is listed below. Took it straight from a book. Works in the sample database but when I take it to mine I get a compile error. Here it is:

' This code enables and disables the shift key from bypassing the startup procedures.
' From Novalis, Susann, "Access 2000 VBA Handbook", Sybex, 1999, pg 716-717.

Public Sub SetByPass(booByPass As Boolean)
Dim db As Database, prp As Property
On Error GoTo Error_SetByPass
Set db = CurrentDb
db.Properties!AllowBypassKey = booByPass

Exit_SetByPass:
Exit Sub

Error_SetByPass:
If Err = 3270 Then
' The property does not exist and needs to be created
Set prp = db.CreateProperty("AllowBypasskey")
prp.Type = dbBoolean ' This is where I get "Compile Error: Can't assign to read-only property"
prp.Value = booByPass
db.Properties.Append prp
Resume Next
Else
MsgBox Err.Number & Err.Description
Resume Exit_SetByPass
End If
End Sub

Any ideas?
 
'The below function and command button code will allow you to use a password protected input box to determine if the Shift key can be disabled or not.

'*You might have to set your "References" to DAO 3.6. When you are viewing a Module, click the Tools menu >>> References >>> Browse for Microsoft DAO 3.6 >>> Select "Files of type: Executable Files (*.exe; *.dll)" (mine is located @ C:\Program Files\Common Files\Microsoft Shared\DAO). Then explicitly dimension your code, i.e... Dim db As DAO.Database, prp As DAO.Property

'Copy this function into a new public module...
Option Compare Database
Option Explicit

Public Function SetProperties(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
On Error GoTo Err_SetProperties
Dim db As Database, prp As Property
Set db = CurrentDb
db.Properties(strPropName) = varPropValue
SetProperties = True
Set db = Nothing
Exit_SetProperties:
Exit Function
Err_SetProperties:
If Err = 3270 Then 'Property not found
Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
db.Properties.Append prp
Resume Next
Else
SetProperties = False
MsgBox "SetProperties", Err.Number, Err.Description
Resume Exit_SetProperties
End If
End Function

'Assign this to the OnClick event of a command (transparent?) button named "bDisableBypassKey"
'Change the "TypeYourBypassPasswordHere" default password
Private Sub bDisableBypassKey_Click()
On Error GoTo Err_bDisableBypassKey_Click
'This ensures the user is the programmer needing to disable the Bypass Key
Dim strInput As String
Dim strMsg As String
Beep
strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & "Please key the programmer's password to enable the Bypass Key."
strInput = InputBox(Prompt:=strMsg, title:="Disable Bypass Key Password")
If strInput = "TypeYourBypassPasswordHere" Then
SetProperties "AllowBypassKey", dbBoolean, True
Beep
MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & "The Shift key will allow the users to bypass the startup options the next time the database is opened.", vbInformation, "Set Startup Properties"
Else
Beep
SetProperties "AllowBypassKey", dbBoolean, False
MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & "The Bypass Key was disabled." & vbCrLf & vbLf & "The Shift key will NOT allow the users to bypass the startup options the next time the database is opened.", vbCritical, "Invalid Password"
Exit Sub
End If
Exit_bDisableBypassKey_Click:
Exit Sub
Err_bDisableBypassKey_Click:
MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
Resume Exit_bDisableBypassKey_Click
End Sub

As for your question, if prp.Type = dbBoolean then what does "dbBoolean" equal in your code?

HTH
 

Users who are viewing this thread

Back
Top Bottom