Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    2

    Question Unanswered: msgboxes & cmds off combo box

    I have a form which contains options for two reports.

    there is an unbound start date and end date field, an option group with 4 set time periods(i.e 1 week or 2 weeks) which just add 7 or 14 days to the end date and an other with all or individual room, if individual is selected then a combo box appears enabled with a list of all the rooms.

    then a cmd button at the bottom is pressed which opens either a single or all room booking timetable. Now that all works fine, but im having problems with msgboxes to stop the reports opening if null for example.

    my code on my cmd button at the moment is:

    Code:
    Private Sub cmdProduceTT_Click()
    Dim stDocName As String
    txtEndDate.SetFocus
    If txtEndDate.Text = Null Then
    MsgBox "Date Missing", vbCritical
    Else
        If cboRoom.Enabled = True Then
            If cboRoom = Null Then
            MsgBox "No Room was entered", vbCritical
            Else
            stDocName = "rptBookingsSingle"
            DoCmd.OpenReport stDocName, acPreview
            End If
        Else
        stDocName = "rptBookingsAll"
        DoCmd.OpenReport stDocName, acPreview
        End If
    End If
    End Sub

    i also need to add something to check if the startdate exists just like the enddate (control name txtEndDate). The two reports run off queries which link back to the controls in this form (frm_BookingTimetable).

    The main problem is that the if cboRoom = Null doesn't stop the report from opening, im thinking iif or isnull statement somewhere?

    symi.

    (picture of form attached for extra clarification)Click image for larger version. 

Name:	frmTimeTable.jpg 
Views:	24 
Size:	80.3 KB 
ID:	9218

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    instead consoder putting some code in the forms on no data event
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Feb 2009
    Posts
    2
    Quote Originally Posted by healdem
    instead consoder putting some code in the forms on no data event
    cheers never noticed the no data event on reports. i will give it a look.

    EDIT: Okey its working now, apart from one thing. when there isnt any data in the report i need to close it.
    so on NoData i put a msgbox and then DoCmd.Close but it comes up with an error message of run-time error '2585': This action can't be carried out while processing a form or report event.
    anyone got any ideas of how i could close the report. I tried a macro with the msgbox and close cmd in but i get the same error.
    Last edited by symi; 02-14-09 at 19:36.

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You need to put

    Cancel = True

    in the report's No Data event, which will stop it from opening (so you won't want the DoCmd.Close). That will also require you trap for error 2501 in the code that opens the report.
    Paul

Posting Permissions

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