Share via

DoCmd.OpenForm Troubleshooting

Anonymous
2018-06-06T17:15:00+00:00

this code works however if there is a duplicate last name it goes to the first entry rather than the last entry

Private Sub Text117_DblClick(Cancel As Integer)

DoCmd.OpenForm "tblReport", acNormal, , "[Last Name] = '" & Me![Last Name] & "'"

End Sub

So I try to specify by the unique ID that is assigned to each entry. I put this code in MS Access 2016, to select the specific ID. I'm not sure why I get a "Run-time error '3464': Data type mismatch in criteria expression.

Private Sub ID_DblClick(Cancel As Integer)

DoCmd.OpenForm "tblReport", acNormal, , "ID = '" & Me![ID] & "'"

End Sub

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2018-06-06T17:59:00+00:00

    Oh this explains it thank you again!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2018-06-06T17:58:36+00:00

    Thank you that solved the problem! why is that? if you can break it down for me? or send me a link because I was reading something along the lines of if it is a number there is a difference but I still don't know why.

    Was this answer helpful?

    0 comments No comments
  3. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2018-06-06T17:18:15+00:00

    I should have added that dates would use:

    DoCmd.OpenForm "tblReport", acNormal, , "[StartDate] = #" & Me!txtStartDate & "#"

    Numbers don't require delimiters like quotes and #.

    Was this answer helpful?

    0 comments No comments
  4. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2018-06-06T17:16:44+00:00

    If ID is a number then you need to use:

    DoCmd.OpenForm "tblReport", acNormal, , "ID = " & Me![ID]

    Was this answer helpful?

    0 comments No comments