Type mismatch error on variable

S

Stu

Hi

I have a function which is called when a control is clicked and this
function needs to test whether a check box is true or false. The check
box vould be one of several depending on criteria declared when the
form is opened (shift number and process type) so I've declared
variables and these are set at as part of the form open event. When
I'm trying to test the varaible I get a type mismatch as the variable
is declared as a string but that's only the name of the control I want
to test and I can't get the IF statement to test the control itself.
I'm sure this must be possible but I just can't figure out how. Any
help would be appreciated.

Function ExpProcessComplete()

Dim CurDate As Date
Dim strUpdateSQL As String
Dim strRequired As String
Dim strDateField As String
Dim strCompleteField As String
Dim strShiftField As String
Dim strCompFieldTest As String
Dim intOrderQty As Integer
Dim strShift As Integer
Dim strProcess As Integer

CurDate = Date + Time
strShift = Forms!frmOpenProcessInput!frmShift.Value
strProcess = Forms!frmOpenProcessInput!FrmProcess.Value

Select Case strProcess
Case "1" ' Cutting
strRequired = "CutReqd"
strDateField = "CutDate"
strCompleteField = "Cut"
strShiftField = "CutShift"
strPartCompField = "PartCut"
strPartCompQtyField = "PartCutQty"
strPartCompDateField = "PartCutDate"
(.....rest of case statement)
End Select

If (strCompleteField = False) Then

DoCmd.SetWarnings False

It's at this point that I get a type mismatch error.

Thanks

Stu
 
D

Douglas J. Steele

strCompletedField is the name of the control on which form?

If it's the current form, use:

If (Me.Controls(strCompletedField) = False) Then

If it's on a different form, use:

If (Forms!FormName.Controls(strCompletedField) = False) Then
 
G

Guest

But "strCompletedField" is defined as type string which has a value of "Cut".
Then he tries comparing it to a boolean value:

'---snip---
If (strCompleteField = False) Then
'---snip---

You can't compare a string to a boolean.


You also have:

Dim strProcess As Integer
strProcess = Forms!frmOpenProcessInput!FrmProcess

So, strProcess is an integer, but then in the Select statement you have

Case "1" ' Cutting

One as a string?? I would use:

Case 1 ' Cutting



BTW, if you want the date and time in "CurDate", it would be better to use

CurDate = Now()


HTH
 
M

missinglinq

Dim strCompleteField As String
If (strCompleteField = False) Then

Looks like you're trying to assign a non-string value (False) to a string,
hence a type mismatch. Perhaps you mean if the string contains a null value
or a zero length string?
 
S

Stu

Thanks Doug

That worked fine

Stu
strCompletedField is the name of the control on which form?

If it's the current form, use:

If (Me.Controls(strCompletedField) = False) Then

If it's on a different form, use:

If (Forms!FormName.Controls(strCompletedField) = False) Then
 
S

Stu

Thanks Steve

I take your point about the strProcess being an integer and I shouldn't
quote it. The main point of my post was that the strCompletedField
variable has a value of Cut and "Cut" is the name of a Boolean field
who's value I need to test. Doug's suggestion of using Me.controls
does exactly what I wanted.

Cheers

Stu
 
G

Guest

I understand now what you were trying to do. Thank goodness for the MVP's
like Doug to straighten us out !! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top