Van,
That was some ugly coding, wasn't it??? Why do you think I needed
help??? Your "untested" code worked great!! I'm not sure I understand
the < -1 though. I've tried to logically think through it, but I'm not
getting it. As far as the inner IF on the msgbox...it was supposed to
say = vbok, but I left that out. Surprised it was working! As far as
why I do it that way, I guess the only good answer I can come up with
is, I've always done it that way. Thank you very much for that and I
hope someday I can think of code on the fly like that, test it, and
have it work!! Also, thank you for putting it on two lines...I hadn't
done that yet.
Just to show you the big picture (and honestly I'm anxious to see what
you say), this is the code that goes with the Select Case in the other
thread. You'll see why I wanted to consolidate statements. My Dlookup
isn't working, but I'll worry about that in a minute:
Dim phoneX As Integer
Select Case frmSearch
Case 1 'company button is selected
'check to see if more than one has data
If (Not IsNull(Me.txtCoCOID)) + (Not IsNull(Me.txtCoPhone)) + _
(Not IsNull(Me.cboCoName)) < -1 Then
MsgBox "There is more than one field with information." &
vbCrLf & _
"Please choose only one field to search for.", _
vbCritical + vbOKOnly, "Error!"
ElseIf Not IsNull(Me.txtCoCOID) Then 'COID has data only
Select Case frmSearch & frmOptions
Case 1 & 1
DoCmd.OpenReport "newcorec", acViewPreview, ,
"coid=" & Me.txtCoCOID
Case 1 & 2
DoCmd.OpenReport "companyrecord", acNormal, ,
"coid=" & Me.txtCoCOID
Case 1 & 3
DoCmd.OpenForm "companymain", acNormal, , "coid=" &
Me.txtCoCOID
End Select
ElseIf Not IsNull(Me.cboCoName) Then 'Company Name has data
only
Select Case frmSearch & frmOptions
Case 1 & 1
DoCmd.OpenReport "newcorec", acViewPreview, ,
"coid=" & Me.cboCoName.Column(0)
Case 1 & 2
DoCmd.OpenReport "companyrecord", acNormal, ,
"coid=" & Me.cboCoName.Column(0)
Case 1 & 3
DoCmd.OpenForm "companymain", acNormal, , "coid=" &
Me.cboCoName.Column(0)
End Select
ElseIf Not IsNull(Me.txtCoPhone) Then 'Phone # has data only
phoneX = DLookup("coid", "compmain", "phone = " &
Forms!frmSearch!txtCoPhone)
Select Case frmSearch & frmOptions
Case 1 & 1
DoCmd.OpenReport "newcorec", acViewPreview, ,
"coid=" & phoneX
Case 1 & 2
DoCmd.OpenReport "companyrecord", acNormal, ,
"coid=" & phoneX
Case 1 & 3
DoCmd.OpenForm "companymain", acNormal, , "coid ="
& phoneX
End Select
End If
End Select
Angi - 28 Apr 2005 08:19 GMT
Before you tell me, I just realized that the second select case
frmSearch is redundant. I didn't plan it to be but the If statement
had to go before the select case, so that's what happened. Because I
check the frmSearch first, I only need to check the frmOptions. DUH!!
Sleep deprivation...it's a bad, bad thing!
Van T. Dinh - 28 Apr 2005 08:37 GMT
1. True is internally stored as -1.
If 2 or more TextBoxes have entry, the sum of the Boolean expressions will
be -2 or -3 and the If condition will become True and the code will display
the MsgBox.
2. If "phone" is a Text field, you need to enclose the explicit value (you
pass in) with String delimiter, i.e. single or double quote. Try:
phoneX = DLookup("coid", "compmain", _
"phone = '" & Forms!frmSearch!txtCoPhone & "'")
3. I would suggest you do pseudo-code on paper first before actually writing
detailed code. This way, you can see the picture clearly and eliminate
unnecessary conditions / checks.
You can also "trace" the code logically and see if the logic is correct and
efficient before spending time doing detailed (actual) code.
For example, in the long code you posted, once you go into the first case of
the outer Select Case statement, frmSearch value _must_be 1 and therefore in
the (inner) Select Case statement(s), you don't need to check the value of
frmSearch again!
It sounds like you are going to end up with nested Select Case but the the
inner Select Case statements will be much simpler.
HTH
Van T. Dinh
MVP (Access)
> Van,
> That was some ugly coding, wasn't it??? Why do you think I needed
[quoted text clipped - 65 lines]
> End If
> End Select
Angi - 28 Apr 2005 08:48 GMT
Van,
Forgot about the -1 being True. The dlookup works now...that was the
problem. I knew how to fix it, I just had to many "'s in there. Did
you see my post right before yours about being redundant? I knew you
were going to call me on that! Believe it or not, I DID do the pseudo
code first...but I didn't know the IF couldn't go between the Select
Case and Case code until I typed it in and got the error. After that,
the flow of my code changed. It's still good to know how to use more
than 1 variable with Select Cases. I use them a lot! Search form
works great now and I consolidated 5 forms into one, so I feel good.
Thanks for all your help!!
Take care,
Angi
Van T. Dinh - 28 Apr 2005 08:52 GMT
I saw you post after since it took my a while to compile my post.
Van T. Dinh
MVP (Access)
> Van,
> Forgot about the -1 being True. The dlookup works now...that was the
[quoted text clipped - 10 lines]
> Take care,
> Angi