Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    disable control (Access 2000)

    On my form i have a command control to open a report after i have made a given order.
    I have the following event in the OnClick command:

    Private Sub CmdStockList_Click()
    Dim stLinkCriteria As String
    Dim stDocName As String
    stLinkCriteria = "orderid = " & OrderID
    stDocName = "StockList"
    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

    If i click the button without having selected an order, then i receive the following message:

    runtime error 3075 extra ) in query expression,which is normal ganing no order.
    Can you help me make the button inactive if i have seklected no order? I do not want to have the
    message runtimeerror 3075, just to make my button disabled and possibly dimmed? I mean to make my button undimmed only i have done an order?

  2. #2
    Lounger
    Join Date
    Mar 2002
    Location
    St Albans, Hertfordshire, England
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: disable control (Access 2000)

    Aral - in form design view set the enabled property to false - this will ensure that when the form opens the button cannot be selected.

    In the OrderID field, set the onchange event to read
    if isnull(me!orderID) then
    exit sub
    else
    me!CmdStockList.enabled = true 'enable the button
    me!CmdStockList.setfocus 'set focus to the button (nice touch for user)
    endif

    also, change the CMDStockList_Click event as follows:

    Private Sub CmdStockList_Click()
    Dim stLinkCriteria As String
    Dim stDocName As String
    stLinkCriteria = "orderid = " & OrderID
    stDocName = "StockList"
    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
    me!OrderID = Null 'clear the listed Order ID
    me!CmdStockList.Enabled = false 'and disable the button again!

    end sub

    If you have set to disallow nulls, then use the empty string "" validation instead.

    Hope that helps

    Chris

Posting Permissions

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