Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use of Form name in a string (Access 2000)

    I have a database that was used by only those that could update the table. They now want to open it up to others with the forms in View only format. I have written the code that will take each form and open it in design mode and change the properties to prevent update, deletes and adds. This is the code I use:
    ' Open form in design mode for property changes
    DoCmd.OpenForm "frm_Menu_Task_Maint", acDesign
    If [Forms]![form1]![Read-Only_chkbx] Then ' Test for read only user
    [Forms]![frm_Menu_Task_Maint].CloseButton = False
    [Forms]![frm_Menu_Task_Maint].MinMaxButtons = 0
    [Forms]![frm_Menu_Task_Maint].PopUp = True
    [Forms]![frm_Menu_Task_Maint].Modal = True
    [Forms]![frm_Menu_Task_Maint].ControlBox = False
    [Forms]![frm_Menu_Task_Maint].ShortcutMenu = False
    Else
    [Forms]![frm_Menu_Task_Maint].CloseButton = True
    [Forms]![frm_Menu_Task_Maint].MinMaxButtons = 3
    [Forms]![frm_Menu_Task_Maint].PopUp = False
    [Forms]![frm_Menu_Task_Maint].Modal = False
    [Forms]![frm_Menu_Task_Maint].ControlBox = True
    [Forms]![frm_Menu_Task_Maint].ShortcutMenu = True
    End If
    DoCmd.SetWarnings (False)
    DoCmd.Save acForm, "frm_Menu_Task_Maint"
    DoCmd.SetWarnings (True)
    DoCmd.OpenForm "frm_Menu_Task_Maint"

    What I would like to do is take this code and place it into a module and have the form name passed to the module. This way I would only have one place where this code is executed. I want to do something like this:

    (in my code to open a new form)

    response =OpenaForm("frm_Menu_Task_Maint")

    Public Function OpenaForm(whatForm As String) As Boolean
    On Error GoTo Err_OpenaForm

    DoCmd.OpenForm whatForm, acDesign
    If [Forms]![form1]![Read-Only_chkbx] Then
    whatForm.CloseButton = False
    whatForm.MinMaxButtons = 0
    whatForm.PopUp = True
    whatForm.Modal = True
    whatForm.ControlBox = False
    whatForm.ShortcutMenu = False
    Else
    whatForm.CloseButton = True
    whatForm.MinMaxButtons = 3
    whatForm.PopUp = False
    whatForm.Modal = False
    whatForm.ControlBox = True
    whatForm.ShortcutMenu = True
    End If
    DoCmd.SetWarnings (False)
    DoCmd.Save acForm, whatForm
    DoCmd.SetWarnings (True)
    DoCmd.OpenForm whatForm

    OpenaForm = True

    Exit_OpenaForm:
    Exit Function

    Err_OpenaForm:
    MsgBox Err.Description
    OpenaForm = False
    Resume Exit_OpenaForm

    End Function


    Can anyone tell me how I can use the string name here to set the properties. The compiler doesn't recognize whatForm as a string and use the value within it..

    <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15>

    Thank you
    Don
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Use of Form name in a string (Access 2000)

    Hi Don,
    You need something along the lines of:
    <pre>Function FixForm(strFormName As String)
    DoCmd.OpenForm strFormName, acDesign
    With Forms(strFormName)
    .CloseButton = False
    .MinMaxButtons = 0
    .......remaining code here
    End With
    End Function
    </pre>

    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use of Form name in a string (Access 2000)

    Thank you Rory. Works like a charm.

    It's amazing how the obvious is sometimes invisible to you. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> to you..
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •