Results 1 to 6 of 6

Thread: VB Code (2000)

  1. #1
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts

    VB Code (2000)

    I have a contact management database which I would like to query itself whenever it is opened. If there is a contact that requires a return call within the next 30 days I would like the db to display a message box that prompts the user to either click OK (which would open a report displaying data) or NO which would close the message box.

    I have called the following function from the On Current event of the Switchboard form.

    Private Sub Form_Current()
    ' Update the caption and fill in the list of options.

    Me.Caption = Nz(Me![ItemText], "")
    FillOptions

    OpenCallList (True)

    End Sub

    Private Function OpenCallList(Cancel As Integer)
    'Queries database and displays message box if there are calls to _
    return in the next 30 days.

    Dim Msg, Style, Title, Response
    Msg = "There are clients to return calls to. Do you want to view report"
    Style = vbYesNo + vbInformation + vbDefaultButton1
    Title = "Client Follow Up"


    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then
    DoCmd.OpenReport "ReturnCallList", acViewPreview
    ElseIf Response = vbNo Then
    Cancel = True
    End If

    End Function

    Is this code in the correct place? And where and what code would I insert to query the
    Easy Access

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

    Re: VB Code (2000)

    The On current event is not ideal for this - it will not only be executed when the switchboard form is opened, but also each time the user activates a different switchboard page. Instead, use the On Open or On Load event, these are only executed when the form is opened.

    To test, you could use something like this:

    If DCount("*", "Calls", "ReturnCall <= Date() + 30") > 0 Then
    ...
    End If

  3. #3
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: VB Code (2000)

    Thank you for your help Hans.
    One problem has appeared. When I choose to view the report that is generated (by clicking OK) the Switchboard opens to its maximum size. The report I want to open ReturnCallList has "DoCmd.Maximize" in the On Activate event).
    What can I do to keep the Switchboard at its "normal" size and switch the focus from the Switchboard to the report?
    Easy Access

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

    Re: VB Code (2000)

    When you maximize one window within Access, you maximize ALL windows within Access, except for forms with Popup set to Yes. But you don't want to set the Popup property for the Switchboard form to Yes, since it would stay in front of all other windows, including reports.
    The "solution" is to put DoCmd.Restore in the On Deactivate event of the report.

  5. #5
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: VB Code (2000)

    I put the code in the On Deactivate event; however, the Switchboard still has the focus.
    How can I get the focus to shift to the report?
    Easy Access

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

    Re: VB Code (2000)

    DoCmd.OpenReport should automatically shift focus to the report, so I don't understand why the Switchboard form retains focus. Perhaps inserting the following line after the DoCmd.OpenReport line helps:

    DoCmd.SelectObject, acReport, "ReturnCallList"

Posting Permissions

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