By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

Keep getting a type mismatch error...why?

P: 3
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
Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,660
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

P: 3
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 15k+
P: 31,660
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.