DoCmd Open Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lebbsy
    New Member
    • May 2007
    • 55

    DoCmd Open Form

    After displaying search results, I want to be able to double click the identity number field and then the input form SubmissionDetai ls becomes the display form for the results of the data matching value of the selected identity number. With my code below I get a data type mismatch error. Please help me.......
    Code:
    Private Sub IdentityNumber_Click()
    On Error GoTo IdentityNumber_Click_Err
    
        On Error Resume Next
        If (Form.Dirty) Then
            DoCmd.RunCommand acCmdSaveRecord
        End If
        If (MacroError.Number <> 0) Then
            Beep
            MsgBox MacroError.Description, vbOKOnly, ""
            Exit Sub
        End If
        On Error GoTo 0
        DoCmd.OpenForm "SubmissionDetails", acNormal, , "[IdentityNumber]=" & IdentityNumber, , acDialog
        'DoCmd.OpenForm "SubmissionDetails", acNormal, "", "[IdentityNumber]=" & IIf(Nz(IdentityNumber.Value) = vbNullString, "No value.", IdentityNumber.Value & "."), , acDialog
    
        'IIf(Nz(IdentityNumber.Value) = vbNullString, "No value.", "Value is " & IdentityNumber.Value & ".")
    
        If (Not IsNull(IdentityNumber)) Then
            TempVars.Add "CurrentID", "[IdentityNumber]"
        End If
        If (IsNull(IdentityNumber)) Then
            TempVars.Add "CurrentID", "Nz(DMax(""[IdentityNumber]"",[Form].[RecordSource]),0)"
        End If
        DoCmd.Requery ""
        DoCmd.SearchForRecord , "", acFirst, "[IdentityNumber]=" & TempVars!CurrentID
        TempVars.Remove "CurrentID"
    
    
    IdentityNumber_Click_Exit:
        Exit Sub
    
    IdentityNumber_Click_Err:
        MsgBox Error$
        Resume IdentityNumber_Click_Exit
    
    End Sub
    Last edited by NeoPa; Feb 16 '09, 11:35 AM. Reason: Please use the [CODE] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    As a full member now, you should know that we expect your code to be posted in [CODE] tags (See How to Ask a Question).
    This makes it easier for our Experts to read and understand it.

    Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use the tags in future.

    Administrator.

    PS. Please indicate (at least) which line the reported error occurs on.

    Comment

    • Lebbsy
      New Member
      • May 2007
      • 55

      #3
      Thank you NeoPa. I tried to do so but my window would allow me to insert tags so I ended up sending without them. Anyway just figured out where the problem was. Instead of making the IdentityNumber on the right a string, I had made it a number. So I just put some quotes around it and it was solved.

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        My guess is that [IdentityNumber] is defined in your table as Text, which it should be, so your Where clause

        "[IdentityNumber]=" & IdentityNumber

        needs to be

        "[IdentityNumber]= '" & Me.IdentityNumb er & "'"

        Linq ;0)>

        Comment

        • Lebbsy
          New Member
          • May 2007
          • 55

          #5
          Thanks missinglinq,

          I realised that that was the problem. Thanks for the reply.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            Originally posted by Lebbsy
            Thank you NeoPa. I tried to do so but my window would allow me to insert tags so I ended up sending without them.
            No worries then. Maybe this will help :

            Tags are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [ CODE ] tags has a hash (#) on it. You can choose which editor to use in your profile options (Look near the bottom of the page).

            Comment

            Working...