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

AcadDocument_Activate event - VBA

Status
Not open for further replies.

basepointdesignz

Programmer
Jul 23, 2002
566
GB
Hi folks,

Does anyone know how to trigger the AcadDocument_Activate event so that a form is displayed so the user can enter his/her ID?

I've tried what the Help pages in AutoCAD say and it doesn't work, here's what I've got...

Code:
Private Sub AcadDocument_Activate()
loginform.Show
End Sub

....which is basically what the Help pages have..

Any suggestions??

Cheers,

Renegade..
 
Hi borgunit,

Can you please ellaborate on that. I already have the program as an embedded project (sorry, forgot to mention that bit, ooops!), so the form is already loaded..

Here's what the help pages say about....

AcadDocument_Activate..
Code:
Private Sub AcadDocument_Activate()
    ' This example intercepts a drawing Activate event.
    '
    ' This event is triggered when a drawing window becomes active.
    '
    ' To trigger this example event: Either open a new drawing or switch from
    ' one drawing window to another

    MsgBox "You have just activated a drawing!"
End Sub

..and AppActivate...
Code:
Public WithEvents ACADApp As AcadApplication    ' Use with Application Event Examples
Sub Example_AcadApplication_Events()
    ' This example intializes the public variable (ACADApp)which will be used
    ' to intercept AcadApplication Events
    '
    ' The VBA WithEvents statement makes it possible to intercept an generic object
    ' with the events associated with that object.
    '
    ' Before you will be able to trigger any of the AcadApplication events,
    ' you will first need to run this procedure.
    
    ' We could get the application from the ThisDocument object, but that would
    ' require having a drawing open, so we grab it from the system.
    Set ACADApp = GetObject(, "AutoCAD.Application")
End Sub
Private Sub ACADApp_AppActivate()
    ' This example intercepts an Application AppActivate event.
    '
    ' This event is triggered when the AutoCAD application receives focus
    '
    ' To trigger this example event:
    '     1) Make sure to run the example that initializes
    '     the public variable (named ACADApp) linked to this event.
    '
    '     2) Switch focus from AutoCAD to another Windows application
    '     and then back again

      MsgBox "AutoCAD was just activated!"
End Sub

I've tried it every which but loose and still no joy..

I'm confuzzed!!

Renegade..
 
So.. you are trying to load a form that is loaded from a separately loaded embedded macro?
 
Hi borgunit,

The embedded project has one module and one form. The form is the
Code:
loginform
.
All the code for the login procedure is on the form. The only code in the module is the macro (AcadDocument_Active) that shows the form (it should trigger the macro to load the form when any drawing with that embedded project in it is opened).
Well, this is what I hoped it would do but when the drawing is opened (including from fresh - ie.. first drawing of the day), nothing happens (except the drawing opening of course).

What am I missing? I don't need a link to the Acad.dvb and/or the Acad.lsp file do I - the help files do say that I should but we all know what they're like!!

Thanks,

Renegade..
 
is this problem solved....i think ur first code works...
theoretically it is correct..
just show the form in the activate event of the drawing

 
Hi,

I managed to do it by using adding a section to the ACAD2000.lsp file, which initiates the log-in form upon any drawing being opened..

Here's the code I used for the Log-In form:
Code:
Option Explicit
'********************
' DECLARE VARIABLES..
'********************
Dim pswd1 As String  'Password 1..
Dim pswd2 As String  'Password 2..
Dim response As Integer  'Answer to msgbox (Yes/No etc..)
Dim countX As Integer  'CountX is the main number of log-ins..
Dim countZ As Integer  'CountZ is the counter for checking the "Attempt(s)" string..
Dim stringL As Integer  'String length of the Drawing Name..
Dim drawnameX As String  'Edited Drawing Name..
Dim attemptX As String  'Number of attempts the user has to log-in..
'************************
' END DECLARE VARIABLES..
'************************



'*********************
' ENTER THE PASSWORD..
'*********************
Private Sub CommandButton1_Click()

' Input text of passwords. This is simplified as there are only two users,
' but if new passwords need to be created or ammended, code to edit/add Registry
' Keys can be used. Alternatively, A small Access database can be used to store these values..
pswd1 = TextBox1.Text
pswd2 = TextBox1.Text

' Set password..
pswd1 = "bpd"
pswd2 = "roadrunner"

' Check if the textbox is empty..
If TextBox1.Text = Empty Then
    MsgBox "Please enter a valid password..", vbExclamation, " Password Entry: Nil.."
    Exit Sub
End If

' Test pswd entry..
If TextBox1.Text = pswd1 Or TextBox1.Text = pswd2 Then  'Password correct..
        If TextBox1.Text = pswd1 Then 'If password = pswd1 then OK..
            MsgBox "The password entered was correct.." & Chr(10) & " Hello Paul, " & ThisDrawing.Name & " is now open for editing..", vbExclamation, " Log-in was successful.."
        ElseIf TextBox1.Text = pswd2 Then 'If password = pswd2 then OK..
            MsgBox "The password entered was correct.." & Chr(10) & " Hello Mark, " & ThisDrawing.Name & " is now open for editing..", vbExclamation, " Log-in was successful.."
        End If
    ThisDrawing.Activate
    loginform.Hide
ElseIf TextBox1.Text <> pswd1 Then  'Password incorrect..
        countX = countX + 1  'Add 1 to the counter (number of log-ins)..
        countZ = countZ - 1  'Remove 1 from the counter(&quot;attempts&quot; text..
        
        If countZ = 1 Then
            attemptX = &quot;attempt&quot; 'If the counter = 1, then singular string..
        Else: attemptX = &quot;attempts&quot; 'If the counter <> 1, then plural string..
        End If
        
        
        MsgBox &quot;The password entered was incorrect..&quot; & Chr(10) & &quot;Please try again - You now have &quot; & countZ & &quot; &quot; & attemptX & &quot; left..&quot;, vbExclamation, &quot; Password Incorrect..&quot;
        TextBox1.SetFocus
        TextBox1.Text = &quot;&quot;
 End If
 
 
 ' If log-in unsuccessful x3 then..
        If countX = 3 Then  'If all three attempts have been used..
        MsgBox &quot;You haven't got authority to edit this drawing..&quot; & Chr(10) & Chr(10) & &quot;This session of AutoCAD will now close!!..&quot;, vbCritical, &quot;Log-in Unsuccessful..&quot;
            ThisDrawing.Application.Quit
        End If
        'End If
End Sub
'*********************
' ENTER THE PASSWORD..
'*********************

'********************
' ENTER KEY PRESSED..
'********************
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then
    CommandButton1_Click 'If user presses ENTER; this acts just as if user click CommandButton 1..
End If
End Sub
'********************
' ENTER KEY PRESSED..
'********************

'************
' FORM LOAD..
'************
Private Sub UserForm_Initialize()
' Filter out the drawing name (removes the extension)..
stringL = Len(ThisDrawing.Name) - 4
drawnameX = Mid(ThisDrawing.Name, 1, stringL)

loginform.Caption = &quot; User Log-in: &quot; & drawnameX & &quot;..&quot;
TextBox1.SetFocus 'Set focus to the textbox..
countX = 0  'Set main counter to 0..
countZ = 3  'Set text-check counter to 3..
End Sub
'************
' FORM LOAD..
'************

'**************
' FORM UNLOAD..
'**************
' If the user attempts to bypass the log-in by closing the form, the Application will close..
Private Sub UserForm_QueryClose(Cancel As Integer, closemode As Integer)
response = MsgBox(&quot;By closing this form, AutoCAD will also close..&quot; & Chr(10) & &quot;Are you sure you want to exit?..&quot;, vbQuestion + vbYesNo, &quot;Close AutoCAD session..&quot;)
        If response = vbNo Then
            Cancel = 1
        End If
        If response = vbYes Then
            ThisDrawing.Application.Quit  'Close the application..
        End If
End Sub
'**************
' FORM UNLOAD..
'**************


Here's the AutoLISP code added to the ACAD2000.lsp file:
Code:
(defun S::STARTUP()
     (command &quot;_-vbarun&quot; &quot;login&quot;)
)

In the main module of the Log-in form:
Code:
' LOG-IN..
Sub login()
loginform.Show
End Sub


Now everytime a drawing is opened, the log-in form is initiated..

Try it, altering the code to suit yours of course..

Please let me know if this worked for you..



Cheers,

Renegade..


BULLET-PROOF DESiGNZ
renegade@tiscali.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top