Results 1 to 9 of 9
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237

    Forms VBA code for form completely blank

    Hi to All,


    I have form Form1 with a command button cmdMemberName with the following VBA code:
    Code:
    Private Sub cmdMemberName_Click()
    
    On Error GoTo ProcError
    
    Dim strWHERE As String
        
        If cboBookStatusId = 2 Then
         strWHERE = "[fkBookId] = " & Forms!frmBooksUsers.txtpkBookId
            DoCmd.OpenForm "frmNameOfMember", , , strWHERE, acFormReadOnly
        Else
            MsgBox "The selected book is not loaned" 
        End If
            
    ExitProc:
        Exit Sub
    ProcError:
        MsgBox "Error " & Err.Number & ": " & Err.Description & ", " _
              & vbCritical, "Error in cmdMemberName_Click Procedure..."
        Resume ExitProc
    
    End Sub
    The second form frmNameOfMember will open completely blank if there is no record to display.
    How can I have a message box informing the user that no records exist?

    Thanks in advance
    Khalil

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    something like this to test for the record:

    Code:
    if Dcount("[id]", "table","[id]=" & txtID ) = 0 then
       msgbox "There is no record."
    else
       docmd.openform "fMyForm,,,"[id]=" & txtID
    endif

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,798
    see http://allenbrowne.com/casu-20.html

    includes work arounds.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237
    Hi,
    I read Allen Browne article at:
    http://allenbrowne.com/casu-20.html
    Condition (a) applied for my case:
    "The form is opened with a WhereCondition that yields no records."


    I used the procedure suggested in the site and have the following code:
    Code:
    
    Private Sub Form_Open(Cancel As Integer)
    
    
        If Me.RecordsetClone.RecordCount = 0 Then
            Cancel = True
            MsgBox "No records"
        End If
    
    
    End Sub


    Clicking the cmdMemberName on Form1 shows the Message box of the form frmNameOfMember. Clicking the OK button of the dialogue box ends up with Run-time error 13: Type mismatch
    When I click Debug it shows the error procedure of cmdMemberName button on Form1:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	9 
Size:	4.9 KB 
ID:	44670
    any Ideas?

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,409
    Try this way:
    Code:
                MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdMemberName_Click" & "."
    or to include the critical icon

    Code:
              MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error in procedure cmdMemberName_Click..."
    Last edited by davegri; 03-18-2021 at 12:16 PM. Reason: another option

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,798
    Just to add an explanation, you are trying to pass a literal text/string value as a comma separator (",") that's part of the function argument syntax. The comma separator in the function arguments should not be quoted.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237
    I tried the code for the error message and have following:

    Error 2501: The OpenForm action was canceled

    Clicking the OK button of the message closes it.
    Can I have something more simple for the user?

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,409
    You can use the error handler for the procedure causing the error to ignore it:

    Code:
    Err_Handler:
        Select Case Err
            Case 2501   'user cancelled, ignore
            Case Else
                MsgBox Err & ", " & Err.Description & " Called from form " & frm.Name
        End Select
        Resume Exit_Handler
    End Sub

  9. #9
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237
    Thank you all.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 01-20-2020, 11:33 AM
  2. Subform is completely blank when opened.
    By Summit_IT in forum Forms
    Replies: 16
    Last Post: 06-19-2019, 01:17 PM
  3. Replies: 6
    Last Post: 09-18-2018, 11:40 AM
  4. Replies: 4
    Last Post: 01-20-2016, 02:24 PM
  5. Replies: 6
    Last Post: 01-24-2014, 07:57 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums