error 13 type mismatch

Jimcb8

Registered User.
Local time
Today, 09:03
Joined
Feb 23, 2012
Messages
98
I keep getting an error 13 type mismatch in the statement where I use DCOUNT
I am simply trying to get the number of records for a specific [ClientId] and [Gender] is equal to Male
I have implemented the suggestion of my previous post done on yesterday and am still stuck.
I tried to change Answ to string and also to integer with no luck
If anyone could please help me I would be grateful
Thanks so much
Jim
_________________________________________________________
Option Compare Database
Option Explicit
Private Sub Form_AfterUpdate()
Dim malesx As Integer
Dim Answ As String
Dim mycriteria As String
Dim malecst As String
malecst = "Male"
MsgBox malecst ' value of malecst is Male
MsgBox "'" & Forms!HomePage!NavigationSubform.Form!ClientID & "'"
mycriteria = "'" & Forms!HomePage!NavigationSubform.Form!ClientID & "'"
MsgBox mycriteria & " mycriteria" 'contents on execution is 'ACOSCA' which is the correct key for [ClientId] (actual key is ACOSCA without the quotes)
Answ = Forms!HomePage!NavigationSubform.Form!.[#MalesHousehold] 'Answ is the contents of [#MalesHousehold] before and is ok
MsgBox Answ
Answ = DCount("[Gender]", "Household Information", "[ClientId]= 'mycriteria &'" And "[Gender]= 'malecst'&") 'this is command that I get error 13 type mismatch
Forms!HomePage!NavigationSubform.Form!.[#MalesHousehold] = Answ
End Sub
____________________________________________________________

[Gender] is defined as a string
[Clientid] is defined as a string
[#MalesHousehold] is defined as a integer
 
Code:
Answ = DCount("[Gender]", "Household Information", "[ClientId]= '" & mycriteria & "' And [Gender]= '" & malecst & "'")
 
Sorry for being a pest, but I do want this feature to work. My users are not very computer savy.
The code below does work for a particular ClientId!!!
I am having problems when I want to add another criteria to count the Males for that Clientid.
Specifically I want to say for this ClientId And for only Gender=Males

I get syntax errors or type mismatch or run time errors.

If anyone could help me to add this additional criteria I would be very grateful.

Gender is string
ClientId is a string

Thanks so much
Jim

PS for some reason I no longer get the prompt to THANK the person who helped me????


___________________________________________________________
Option Compare Database
Option Explicit
Private Sub Form_AfterUpdate()
Dim Answ As String
Dim mycriteria As String
Dim malecst As String
malecst = "Male"
MsgBox malecst ' value of malecst is Male
MsgBox "'" & Forms!HomePage!NavigationSubform.Form!ClientID & "'"
mycriteria = "'" & Forms!HomePage!NavigationSubform.Form!ClientID & "'"
MsgBox mycriteria & " mycriteria" 'contents on execution is 'ACOSCA' which is the correct key for [ClientId] (actual key is ACOSCA without the quotes)
Answ = Forms!HomePage!NavigationSubform.Form!.[#MalesHousehold] 'Answ is the contents of [#MalesHousehold] before and is ok
MsgBox Answ
Answ = DCount("[Gender]", "Household Information", "[ClientId]= '" & Forms!HomePage!NavigationSubform.Form!ClientID & "'")
' The above code correctly counts all of the records for the ClientId.
Forms!HomePage!NavigationSubform.Form!.[#MalesHousehold] = Answ
End Sub
 
Have you tried what I already posted? You have not given any feedback on it.
 
Yes
I was not able to make it work.
I have now found out that what is actually stored in [Gender] is a 1 if its Male and a 2 if it is a Female.
So I wasn't getting the correct result because I was testing for "Male" and not a "1"
Given that knowledge I am still trying to get the syntax correct for 2 string variables connected with an And
This version give me a type mismatch

Thank you so much for your patience, I can't tell you how much I appreciate your help.
Thanks again
Jim
_________________________________________________________

Option Explicit
Private Sub Form_AfterUpdate()
Dim Answ As String
Dim mycriteria As String
Dim malecst As String
malecst = "1"
MsgBox malecst ' value of malecst is Male
MsgBox "'" & Forms!HomePage!NavigationSubform.Form!ClientID & "'"
mycriteria = "'" & Forms!HomePage!NavigationSubform.Form!ClientID & "'"
MsgBox mycriteria & " mycriteria" 'contents on execution is 'ACOSCA' which is the correct key for [ClientId] (actual key is ACOSCA without the quotes)
Answ = Forms!HomePage!NavigationSubform.Form!.[#MalesHousehold] 'Answ is the contents of [#MalesHousehold] before and is ok
MsgBox Answ


Answ = DCount("[Gender]", "Household Information", "[Household Information].ClientID='mycriteria'&" And "[Household Information].Gender) = 'malecst'")

MsgBox [Gender]

Forms!HomePage!NavigationSubform.Form!.[#MalesHousehold] = Answ
End Sub
 

Users who are viewing this thread

Back
Top Bottom