Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Arkansas, USA
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Easy VBA help (Access 2k)

    Trying to eliminate some keystrokes and make my code look better.

    Dim fo as object

    Set fo = Forms!frmOrder


    fo!Text152.Locked = True
    fo!Date2HS.Locked = False
    fo!ShipDate.Locked = False
    fo!DateRec.Locked = False
    fo!txtOrder_ID.Locked = True
    fo!Order_Date.Locked = True
    fo!Order_Type.Locked = True

    When I try this, i get an error. What am I doing wrong?

    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Easy VBA help (Access 2k)

    It would have been helpful if you had mentioned what error message you got.

    Are you sure there are no spelling errors in the code?

    If not, you might try

    With Forms!frmOrder
    !Text152.Locked = True
    ...
    !Order_Type.Locked = True
    End With

    If that doesn't work either, try replacing ! before the control names with a period (dot) .

    BTW: Is frmOrder the active form? In that case. you don't need to refer to it at all, you could use Me.Text152 etc. or even plain Text152.

  3. #3
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Arkansas, USA
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Easy VBA help (Access 2k)

    Sorry for not being more specific.

    Here is the way that works...

    Private Sub List5_DblClick(Cancel As Integer)

    DoCmd.OpenForm "frmOrder", acNormal, , "[tblOrders].[Order_ID]=" & Str(Me![list]), acFormEdit, acWindowNormal

    Forms!frmOrder!Text152.Locked = True
    Forms!frmOrder!Date2HS.Locked = False
    Forms!frmOrder!ShipDate.Locked = False
    Forms!frmOrder!DateRec.Locked = False
    Forms!frmOrder!txtOrder_ID.Locked = True
    Forms!frmOrder!Order_Date.Locked = True
    Forms!frmOrder!Order_Type.Locked = True
    Forms!frmOrder!Order_Type.BackStyle = Transparent
    Forms!frmOrder!Order_Type.SpecialEffect = Flat
    Forms!frmOrder!Order_Type.BorderStyle = Transparent
    Forms!frmOrder!Label7.ForeColor = 0
    Forms!frmOrder!Vend_HS_Salesperson.Locked = True
    Forms!frmOrder!Select_Cust.Locked = True
    Forms!frmOrder!Select_Cust.BackStyle = Transparent
    Forms!frmOrder!Select_Cust.SpecialEffect = Flat
    Forms!frmOrder!Select_Cust.BorderStyle = Transparent
    Forms!frmOrder!Label9.ForeColor = 0
    Forms!frmOrder!Cust_Name.Locked = True
    Forms!frmOrder!Cust_DistCenter.Locked = True
    Forms!frmOrder!Cust_Store.Locked = True
    Forms!frmOrder!Cust_Add.Locked = True
    Forms!frmOrder!Text16.Locked = True
    Forms!frmOrder!Cust_Phone.Locked = True
    Forms!frmOrder!Cust_Fax.Locked = True
    Forms!frmOrder!Cust_FedTaxID.Locked = True
    Forms!frmOrder!Cust_Buyer.Locked = True

    Forms!frmOrder!cmdConfirm.Visible = False

    End Sub

    When you double click on a specific record in the list, frmOrder opens with the listed properties.

    Just wondering if there was a better way to code this to substitute typing Forms!frmOrder each time. (Of course I have been using copy and paste, but trying to improve my coding.

    When just using the control names, I get runtime error '424' Object required.

    Thanks again.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Easy VBA help (Access 2k)

    In the first place, declare fo As Form instead of As Object. It shouldn't really matter, but it's cleaner.

    In the second place, the instruction Set fo = Forms!frmOrder should be after DoCmd.OpenForm. If you place it before DCmd.OpenForm, there is no open form yet.

    Otherwise, I don't know. Comparable code works for me.

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Easy VBA help (Access 2k)

    On what command do you get the 424 error?

    have you thought about putting all the code in the OnOpen event of the form you are opening? You can then use Me! as the prefix to all the controls.

  6. #6
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Arkansas, USA
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Easy VBA help (Access 2k)

    Don't want to use in n the onOpen event as different actions e.g clicking on cmd button vs double clicking on list, will open form with different properties. After an initial order is completed, I only want the user to be able to update a few fields.

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Easy VBA help (Access 2k)

    I ask again, On what command do you get the 424 error?

    Have you tried what Hans has said?

    Is there a time delay in loading the form till when you try and reference controls on the form?

  8. #8
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Arkansas, USA
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Easy VBA help (Access 2k)

    not sure what you mean by what command.

    As posted above, it is on the DblClick event of List5 which first runs docmd.openform

    Other than this I do not know what you are asking.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Easy VBA help (Access 2k)

    Presumably, when the error occurs, you get a dialog box with buttons End, Debug and Help.
    If you click Debug, a line of code will be highlighted in yellow. What is the text of that line?

Posting Permissions

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