If-Then Help! Seems simple

B

Brandon Johnson

This question is hard to explain so i will show you an example:

dim strng as string

Set find = CurrentDb.OpenRecordset("Name", dbOpenDynaset)
find.MoveFirst

If chkJob.value = -1 Then
If Len(strng) = 0 Then
strng = "find!title = " & cboJobtitle
Else
strng = strng & " AND find!title = " & cboJobtitle
End If
End If

If chkyears.value = -1 Then
If Len(strng) = 0 Then
strng = "find!yrs = " & txtYrs
Else
strng = strng & " AND find!yrs = " & txtYrs
End If
End If
..
..
..
Do Until find.EOF
If strng Then
ReDim Preserve names(x)
names(x) = find!id
x = x + 1
End If
loop


Im getting a data type runtime error#13 at the bottom where it trys to
do the "if strng then" within the loop. Does anyone have any
suggestions. it would help me out alot.
 
G

Guest

Brandon Johnson said:
This question is hard to explain so i will show you an example:

dim strng as string

Set find = CurrentDb.OpenRecordset("Name", dbOpenDynaset)
find.MoveFirst

If chkJob.value = -1 Then
If Len(strng) = 0 Then
strng = "find!title = " & cboJobtitle
Else
strng = strng & " AND find!title = " & cboJobtitle
End If
End If

If chkyears.value = -1 Then
If Len(strng) = 0 Then
strng = "find!yrs = " & txtYrs
Else
strng = strng & " AND find!yrs = " & txtYrs
End If
End If
..
..
..
Do Until find.EOF
If strng Then
ReDim Preserve names(x)
names(x) = find!id
x = x + 1
End If
loop


Im getting a data type runtime error#13 at the bottom where it trys to
do the "if strng then" within the loop. Does anyone have any
suggestions. it would help me out alot.

"If strng Then" is an evaluation of a boolean, but strng is a string
variable. You're code sees the value of strng as a string rather than as
runable code.

I think you should move the code where you're evaluating the checboxes
inside the Do Until loop and directly evaluate the field values rather than
trying to build a filter string.

Barry
 
G

Guest

Barry is right about the boolean, but as a side note if you start with strng
= "" after movefirst you can do away with the len(strng) and else code, and
just have;

If chkJob.value = -1 Then
strng = strng & " AND find!title = " & cboJobtitle
End If

TonyT
 
J

Jeff L

IF strng Then does not evaluate to True or False. That's why you are
getting an error.
 

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