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

Can't create AllowBypassKey property in db

Status
Not open for further replies.

LittleSmudge

Programmer
Mar 18, 2002
2,848
0
0
GB

I'm following the code supplied in the help file that has worked on many other dbs, but I can't get it to work on this one ( Access 2002 is it matters )

Code:
...
    ChangeProperty "AllowBypassKey", dbBoolean, False
...


Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
    Dim dbs As Database
    Dim prp As Property

    Set dbs = CurrentDb
    On Error GoTo Change_Err
    dbs.Properties(strPropName) = varPropValue
    ChangeProperty = True
Change_Bye:
    Exit Function
Change_Err:
    If Err.Number = 3270 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

The 3270 error duly occurs and on the Set prp = line I get an
Error 13 : Type Missmatch
I know varPropType = 1 ( Boolean ) & varPropValue = False
I can't seen to fathom out what is going wrong


Any ideas ?

G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Try changing the first two lines to:

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

Ed Metcalfe.

Please do not feed the trolls.....
 
Thanks Ed - I've kind of come to a similar solution

I change the Dim prp line to

Dim prp as Object

Late typing allowed it to get through the Set prp = line and then
dbs.Properties.Append prp sorted it all out.


Now I've done the "Create" I can't test your solution but I've a good idea that your was is the 'proper' fiz to my problem :)


Thanks



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
How are ya LittleSmudge . . .

Try changing the header of yur code to the following:
Code:
[blue]Function ChangeProperty(strPropName As String, varPropType As [purple][b]Integer[/b][/purple], varPropValue) As [purple][b]Boolean[/b][/purple]
    Dim dbs As [purple][b]DAO[/b][/purple].Database
    Dim prp As Property[/blue]
You should only have to prefix DAO to Database.

In any event using DAO requires the [purple]Microsoft DAO 3.6 Object Library[/purple] to run. To [blue]check/install[/blue] the library, in any code window click [blue]Tools[/blue] - [blue]References...[/blue] In the listing find the library and [blue]make sure its checked.[/blue] Then using the up arrow, [purple]push it up as high in priority as it will go[/purple]. Click OK.

Calvin.gif
See Ya! . . . . . .
 
Cheers AceMan - doing okay, keeping ( very ) busy. Pressure of work has mean little time for surfing T-T recently.

Fully understand where you're coming from on that.
( DAO3.6 already loaded )

As for the Function's return type - it is literally a copy from the Access Help file and they always seem to type bool responses as Integer. I've often wondered why, but on the basis that Integer works, I've not bothered to go back an make the change.


Keep well Ace



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Roger That LittleSmudge . . .

Since I know you to be [blue]worthy![/blue] . . . I thought I'd open up the skinny on using the Boolean data type as the type returned from a function.

Lets say somewhere in you code you run the function in this thread, and in order for you to continue you need to know if [blue]ChangeProperty()[/blue] was suscessful! This requires a simple return value of [blue]yes[/blue] or [blue]no[/blue] from the function! . . . Code could be something like:
Code:
[blue]   If ChangeProperty(...) then [green]'True[/green]
      'Do This
   Else                        [green]'False[/green]
      'Do That
   Endif[/blue]
Thats all its for . . . an indication of success or failure!

Now check this out . . .
Microsoft said:
[blue]The True keyword has a value equal to -1.

The False keyword has a value equal to 0.[/blue]
Isn't it funny . . . although the return data type of the function is set to integer, you return a boolean type with:
Code:
[blue]   ChangeProperty = True[/blue]
See [blue]my point?[/blue]

Calvin.gif
See Ya! . . . . . .
 
No Ace I don't actually see your point.
( Don't understand the 'skinny' reference either )

BECAUSE

Code:
Dim intA As Integer
intA = 42
If intA Then
    ' This WILL run
Else
    ' This will only run if intA = 0
EndIf

Whilst I fully accept that the True keyword = -1
( Only those with a 'classical' education and understand 2's complement really understand why - oh god I'm showing my age )

HOWEVER
The If statement works on the basis that 0 = False and any other value is Not False ( >>> True )

So setting the return TYPE of the function to Integer works just as well as Boolean


Indeed I put this to good use in some functions that I'ev written myself that should return the Long Integer primary key for a record.
If something goes wrong in the sub routine then I set the return value to zero and exit the function. If all goes well the prime key value is returned.
The calling function simply does an
Code:
If {ReturnedValue} Then
    ' All is well and we proceed
Else
    ' Disaster recovery
End If


What I don't understand is why the Access Help file uses Integer when it is plain that a simple Boolean would do.
( As I said before the sample at the top of the thread was a copy from the help file and I saw no need to waste the time to change it - If it ain't broke - don't fix it )





G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
LittleSmudge . . .

I forgot to mention:
Microsoft said:
[blue]An [purple]If[/purple] statement [purple]considers any non-zero result returned to be true![/purple][/blue]
This is why . . .
Code:
[blue]If {ReturnedValue} Then [green]'ReturnedValue = True[/green][/blue]
. . . works! Its the same as:
Code:
[blue]If {ReturnedValue} = True Then[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top