Compile error - Invalid qualifier

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Light1
    New Member
    • Feb 2008
    • 7

    Compile error - Invalid qualifier

    My form (frmERLogs) for this project (ER Log Book) has a combo box (cboMedicalReco rdNumber) that I want to be able to double click on to bring up a new form (frmPatientInfo rmation) when a name is not already in the list. When I double click on that combo box, I get this message 'Compile error - Invalid qualifier'. Below is the coding for the double click event:
    [code=vb]Private Sub cboMedicalRecor dNumber_DblClic k(Cancel As Integer)

    Dim rs As DAO.Recordset
    Dim strWhere As String
    Const frmPatientInfor mation = "Patients"

    'Set up to search for the current customer.
    If Not IsNull(Me.cboMe dicalRecordNumb er) Then
    strWhere = "cboMedicalReco rdNumber = """ & Me.cboMedicalRe cordNumber & """"
    End If

    'Open the editing form.
    If Not frmPatientInfor mation.AllForms (frmPatientInfo rmation).IsLoad ed Then 'above statement emboldened before code tags added
    DoCmd.OpenForm frmPatientInfor maion
    End If
    With Forms(frmPatien tInformation)

    'Save any edits in progress, and make it the active form.
    If .Dirty Then .Dirty = False
    .SetFocus
    If strWhere <> vbNullString Then
    'Find the record matching the combo.
    Set rs = .RecordsetClone
    rs.FindFirst strWhere
    If Not rs.NoMatch Then
    .Bookmark = rs.Bookmark
    End If
    Else
    'Combo was blank, so go to new record.
    RunCommand acCmdRecordsGoT oNew
    End If
    End With
    Set rs = Nothing


    End Sub[/code]

    The sentence in bold is the part that shows as being a problem. The part 'frmPatientInfo rmation' in front of AllForms(frmPat ientInformation ) is highlighted. Is it supposed to be the project name in front of 'AllForms(frmPa tientInformatio n)? And if so, how is it coded. Nothing I have tried putting in there has changed the error that comes up.

    I am working in Access 2003

    Thanks for any help you can provide.
    Last edited by Stewart Ross; Mar 14 '08, 11:52 AM. Reason: code tags added
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. The reference to the IsLoaded property is incorrect, as you will see if you look at the IsLoaded function provided in the MS Northwind database. The initial reference is not to the form but to the CurrentProject property. Also, the name of the form needs to be passed as either a string variable or as a string literal. String literals should be in quotes. These were missing in your code.

    Your code has other problems as well, not least with the IF...THEN structure which is out of sync in the later part of your code. It is not good practice to mix true IF..THEN..ELSE constructs with single-line IFs, as this makes it difficult to work out the logic of your code.

    I append a corrected version below, with the in-line IFs replaced and an ENDIF swapped at the bookmark end of the code to correct a sequencing error.

    -Stewart
    [code=vb]Private Sub cboMedicalRecor dNumber_DblClic k(Cancel As Integer)

    Dim rs As DAO.Recordset
    Dim strWhere As String
    Const frmPatientInfor mation = "Patients"

    'Set up to search for the current customer.
    If Not IsNull(Me.cboMe dicalRecordNumb er) Then
    strWhere = "cboMedicalReco rdNumber = """ &_
    Me.cboMedicalRe cordNumber & """"
    End If

    'Open the editing form.
    IF Not CurrentProject. AllForms("frmPa tientInformatio n").IsLoaded THEN
    DoCmd.OpenForm frmPatientInfor maion
    End If
    With Forms(frmPatien tInformation)

    'Save any edits in progress, and make it the active form.
    IF .Dirty Then
    .Dirty = False
    END IF
    .SetFocus
    IF strWhere <> vbNullString THEN
    'Find the record matching the combo.
    Set rs = .RecordsetClone
    rs.FindFirst strWhere
    IF Not rs.NoMatch THEN
    .Bookmark = rs.Bookmark
    Else
    'Combo was blank, so go to new record.
    RunCommand acCmdRecordsGoT oNew
    END IF
    END IF
    End With
    Set rs = Nothing
    End Sub[/code]

    Comment

    • Light1
      New Member
      • Feb 2008
      • 7

      #3
      Thanks for your help. I did alter it and although it does not show the same error, it does highlight the same line. When I put my cursor over it now, it shows this beneath it:
      Current Project...=<The expression you entered refers to an object that ...

      I couldn't find a way to view the rest of that statement - if there was more to it. Do you know what that means?

      Thanks also for pointing out some of the other errors.

      Comment

      • Light1
        New Member
        • Feb 2008
        • 7

        #4
        I did find out where to do the step through and find out the whole error message which says the form is either closed or doesn't exist. I know the spelling of the form is correct, so I am trying to find where else it might be breaking.

        Comment

        • Stewart Ross
          Recognized Expert Moderator Specialist
          • Feb 2008
          • 2545

          #5
          Originally posted by Light1
          I did find out where to do the step through and find out the whole error message which says the form is either closed or doesn't exist. I know the spelling of the form is correct, so I am trying to find where else it might be breaking.
          Hi. Have you enclosed the form name in quotes in the IsLoaded expression? If not this alone will give rise to an error. There are also at leaset two subsequent references to the form name in your code which need to be in quotes - to pass the form name as a sytring literal to the properties concerned.
          [code=vb]IF Not CurrentProject. AllForms("frmPa tientInformatio n").IsLoaded THEN
          DoCmd.OpenForm "frmPatientInfo rmaion"
          End If
          With Forms("frmPatie ntInformation")[/code]
          -Stewart

          Comment

          Working...