Results 1 to 10 of 10
  1. #1
    apk19 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    30

    Dealing with Run-time error 2427 with a search form and subform

    Hi all,



    I am having difficulties in dealing with a run-time error on a search form that opens a selected record. Records in the form update as you type into the search box. The opening of the record when there is one is not an issue, but when there are no records I get run-time error 2427.

    Code is:

    Code:
    Private Sub Command69_Click()
        If Me.qrySearchApp_subform.Form.ClientID = "" Then
        MsgBox "No record selected.", vbOKOnly
        Else
        DoCmd.OpenForm "Applicants", , , "ClientID = """ & Me.qrySearchApp_subform.Form.ClientID & """"
        End If
    
    End Sub
    Trying to find a quick fix for the error that will bounce the user back into the form if there are no records. Not sure if the "If" statement should be IsNull or if there should be a Boolean statement instead.

    Any help would be greatly appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    are you sure: Me.qrySearchApp_subform.Form.ClientID is the correct path?
    did you use BUILDER to get this path? (it never gets it wrong)

    also less confusing, you can use single quotes:
    DoCmd.OpenForm "Applicants", , , "[ClientID] = "'" & Me.qrySearchApp_subform.Form.ClientID & "'"


    and it could be null and error , unlike:
    If isNull(Me.qrySearchApp_subform.Form.ClientID)
    so the 1st statement should be:
    on error resume next



  3. #3
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Error 2427 = You entered an expression that has no value. The expression may refer to an object that has no value, such as a form, a report, or a label control. (followed by a name here)
    As Ranman suggested you have used an incorrect name
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    In case the name is correct please try:
    Code:
    Private Sub Command69_Click()
        If isNull(Me.qrySearchApp_subform.Form.ClientID) Then
              MsgBox "No record selected.", vbOKOnly
        Else
              DoCmd.OpenForm "Applicants", , , "ClientID = """ & Me.qrySearchApp_subform.Form.ClientID & """"    'this assumes ClientID is a string
        End If
    
    
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    apk19 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2015
    Posts
    30
    Tried your suggestion Gicu, but I get the same 2427 error.

    Ranman, didn't use the builder but I assumed this is correct as when there are one or more records showing the openform command works.

    "ClientID" is an indexed field for a selected record. There are a few others. Screenshot attached shows when there is no record in the search box.

    I built a query: qrySearchApp, which was then dropped into the form as a subform. As the screenshot should show, the subform is a continuous form.

    Click image for larger version. 

Name:	Search.jpg 
Views:	15 
Size:	25.3 KB 
ID:	43618

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Is the ClientID numeric or text?
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    apk19 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2015
    Posts
    30
    Quote Originally Posted by Gicu View Post
    Is the ClientID numeric or text?
    It's a string: 4 letters and 4 numbers.

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    I think I (we) misunderstood your question. The code you have there makes no sense if looking to open another form ("Applicants") that match the ID in a subform "filtered" by your search box in your main form.
    Code:
    If Me.qrySearchApp_subform.Form.ClientID = "" Then
        MsgBox "No record selected.", vbOKOnly
    Else
        DoCmd.OpenForm "Applicants", , , "ClientID = """ & Me.qrySearchApp_subform.Form.ClientID & """
    End If
    You could use a dCount on the subform's record source (dCount("*","tblTableName","[ClientID] Like '" & Forms!frmYourForm!txtSearchBox & "'")=0) to see if there are no records returned or use the subform recordset.recordcount property:
    Code:
    If Me.qrySearchApp_subform.Form.Recordset.RecordCount =0 Then
        MsgBox "No record selected.", vbOKOnly
    Else
        DoCmd.OpenForm "Applicants", , , "ClientID = """ & Me.qrySearchApp_subform.Form.ClientID & """
    End If
    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #9
    apk19 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2015
    Posts
    30
    Quote Originally Posted by Gicu View Post
    I think I (we) misunderstood your question. The code you have there makes no sense if looking to open another form ("Applicants") that match the ID in a subform "filtered" by your search box in your main form.
    Code:
    If Me.qrySearchApp_subform.Form.ClientID = "" Then
        MsgBox "No record selected.", vbOKOnly
    Else
        DoCmd.OpenForm "Applicants", , , "ClientID = """ & Me.qrySearchApp_subform.Form.ClientID & """
    End If
    You could use a dCount on the subform's record source (dCount("*","tblTableName","[ClientID] Like '" & Forms!frmYourForm!txtSearchBox & "'")=0) to see if there are no records returned or use the subform recordset.recordcount property:
    Code:
    If Me.qrySearchApp_subform.Form.Recordset.RecordCount =0 Then
        MsgBox "No record selected.", vbOKOnly
    Else
        DoCmd.OpenForm "Applicants", , , "ClientID = """ & Me.qrySearchApp_subform.Form.ClientID & """
    End If
    Cheers,
    Vlad

    My apologies, Vlad. My coding abilities are basic at best.

    Your code was perfect. Many thanks!

  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Hey, glad to help!
    Stay safe!
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 5
    Last Post: 08-29-2019, 04:25 PM
  2. Replies: 9
    Last Post: 06-28-2017, 02:40 PM
  3. Run time error 2465 on search form
    By Jims Chan in forum Forms
    Replies: 5
    Last Post: 01-05-2017, 04:00 AM
  4. Replies: 7
    Last Post: 12-18-2015, 11:43 AM
  5. Replies: 2
    Last Post: 07-21-2014, 12:44 PM

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