Results 1 to 4 of 4
  1. #1
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101

    Attach to current form in public procedure

    I am trying to write a public procedure that I can use to enable/disable controls with automatically when I open forms in my database.
    I have written them out on a form by form basis, but that is tedious and I would like to have something that is portable.
    Could someone help me with the proper way to acomplish this?? Thank you

    Public Sub DisAbleSomeControls()
    Dim i As Integer
    Dim c As Control
    Dim db As Database
    Dim f As Form
    Set db = CurrentDb
    Set f = Forms!ActiveForm


    For i = 0 To f.Controls.Count - 1
    Set c = f.Controls(i) 'Grab a control
    If TypeOf c Is ComboBox Or TypeOf c Is TextBox Then
    With c
    'Set Enabled property to False
    .Enabled = False
    End With
    End If
    Next
    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try this:
    (place this in a standard module)
    Code:
    Public Sub DisAbleSomeControls(pFrm As Form)
       Dim i As Integer
       Dim c As Control
       Dim db As Database
       Dim f As Form
       Set db = CurrentDb
       Set f = pFrm
       For i = 0 To f.Controls.Count - 1
          Set c = f.Controls(i)   'Grab a control
          If TypeOf c Is ComboBox Or TypeOf c Is TextBox Then
             With c
                'Set Enabled property to False
                .Enabled = False
             End With
          End If
       Next
    End Sub


    Call it using:
    Code:
    Private Sub Command28_Click()
       Call DisAbleSomeControls(Me)
    End Sub
    Sub Command28_Click is a button on my test form......

  3. #3
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101
    Hi ssanfu, I clicked the star and gave you props for your help, but I saw nothing in this thread so I thought I'd just make sure you got it.(props) Your advise helped greatly. I applied the call portion to the form open event and all works well. Many thanks.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Glad to be of help..
    You ready to mark this solved?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Attach form to a table field?
    By mantooth29 in forum Forms
    Replies: 1
    Last Post: 08-03-2012, 02:46 PM
  2. Replies: 5
    Last Post: 10-26-2011, 02:59 PM
  3. VBA public procedure in a form
    By gg80 in forum Programming
    Replies: 3
    Last Post: 09-12-2010, 04:55 AM
  4. Attach Email to Form
    By Huddle in forum Access
    Replies: 2
    Last Post: 07-22-2010, 12:39 PM
  5. Replies: 1
    Last Post: 04-13-2010, 12:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums