467,883 Members | 1,332 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,883 developers. It's quick & easy.

Keep getting a type mismatch error...why?

The following VBA code, in Access 2003, is to make a button open and populate a form based on the Surname and Period_frm data on a previous form. However, i keep getting a type mismatch error whenever i click the button. I've tried changing the stLinkCriteria2 type to String but the same thing happens. Does anyone know why?

Private Sub IndividualRpt_Click()
On Error GoTo Err_Command12_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stLinkCriteria2 As Date

stDocName = "View report per individual"

stLinkCriteria = "[Surname]=" & "'" & Me![Surname] & "'"
stLinkCriteria2 = "[Period_frm]=" & "'" & Me![Period_frm] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria And stLinkCriteria2

Exit_IndividualRpt_Click:
Exit Sub

Err_IndividualRpt_Click:
MsgBox Err.Description
Resume Exit_IndividualRpt_Click

End Sub
Nov 23 '06 #1
  • viewed: 3136
Share:
3 Replies
NeoPa
Expert Mod 16PB
Try the following modified code.
You had strings in Date fields + some other problems.
Let me know if you want all problems / changes explained.
Expand|Select|Wrap|Line Numbers
  1. Private Sub IndividualRpt_Click()
  2. On Error GoTo Err_Command12_Click
  3.  
  4. Dim stDocName As String
  5. Dim stLinkCriteria As String
  6. 'Dim stLinkCriteria2 As Date
  7.  
  8. stDocName = "View report per individual"
  9.  
  10. stLinkCriteria = "(([Surname]='" & [Surname]  & "') AND " & _
  11.     "([Period_frm]=#" & Format([Period_frm],"M/D/YYYY") & "#))"
  12. 'stLinkCriteria2 = "[Period_frm]=" & "'" & Me![Period_frm] & "'"
  13. DoCmd.OpenForm stDocName, , , stLinkCriteria
  14.  
  15. Exit_IndividualRpt_Click:
  16. Exit Sub
  17.  
  18. Err_IndividualRpt_Click:
  19. MsgBox Err.Description
  20. Resume Exit_IndividualRpt_Click
  21.  
  22. End Sub
Nov 23 '06 #2
Try the following modified code.
You had strings in Date fields + some other problems.
Let me know if you want all problems / changes explained.
Expand|Select|Wrap|Line Numbers
  1. Private Sub IndividualRpt_Click()
  2. On Error GoTo Err_Command12_Click
  3.  
  4. Dim stDocName As String
  5. Dim stLinkCriteria As String
  6. 'Dim stLinkCriteria2 As Date
  7.  
  8. stDocName = "View report per individual"
  9.  
  10. stLinkCriteria = "(([Surname]='" & [Surname]  & "') AND " & _
  11.     "([Period_frm]=#" & Format([Period_frm],"M/D/YYYY") & "#))"
  12. 'stLinkCriteria2 = "[Period_frm]=" & "'" & Me![Period_frm] & "'"
  13. DoCmd.OpenForm stDocName, , , stLinkCriteria
  14.  
  15. Exit_IndividualRpt_Click:
  16. Exit Sub
  17.  
  18. Err_IndividualRpt_Click:
  19. MsgBox Err.Description
  20. Resume Exit_IndividualRpt_Click
  21.  
  22. End Sub

Thanks a lot, NeoPa. The code worked nicely after i made the necessary amendments. I appreciate this!!!
Nov 24 '06 #3
NeoPa
Expert Mod 16PB
I'm glad to hear it worked for you :).
Nov 24 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by LJgrnl | last post: by
reply views Thread by news.paradise.net.nz | last post: by
6 posts views Thread by Howard Kaikow | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.