472,807 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,807 software developers and data experts.

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
3 3513
NeoPa
32,534 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
32,534 Expert Mod 16PB
I'm glad to hear it worked for you :).
Nov 24 '06 #4

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

Similar topics

1
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to...
0
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
1
by: MovnOn | last post by:
I'm writing a program that uses a COM object. If I were writing this code in VB6, the signature of the method of the COM object I need to use would be: saveMemo (Collection) The method takes a...
6
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The...
1
by: jodyblau | last post by:
I have a database which works fine until I create and MDE file. Once I create the MDE, when I open a particular form I get a "Type Mismatch" error. Because its an MDE file, I can't step through...
2
DonRayner
by: DonRayner | last post by:
This one has me stumped. I'm getting a "Type Mismatch" error on one of my forms when it's being opened. It's hapening before the forms "On Open" event, I stuck a msgbox in there to check and I'm...
1
by: nckinfutz | last post by:
hello, I am having a problem with an access database. this is not my database and I did not create it, nor am I very good at access. however, I am a network engineer and that is why this problem...
4
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working,...
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.