Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

p[rogramatic error on query

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
US
I have a query designed programmatical to retrieve names out of a database based on a month selected combo box. I receive the below error if a month is selected that has no names associated with it:

The expression On Click you entered as the event property setting producted the following error:

The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
There may have been an error evaluating the function, event or macro.

I want the code to be able to know if there are no names assocaitated with a given month selected that message box will appear letting the user know that.

my code is below:

Dim db As Database
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim strVAR As String
Dim stridowner As String
Dim X As Integer

If Me.cmbdatephase.Value = "January" Or Me.cmbdatephase.Value = "February" Or Me.cmbdatephase.Value = "March" Or Me.cmbdatephase.Value = "April" Or Me.cmbdatephase.Value = "May" Or Me.cmbdatephase.Value = "June" Or Me.cmbdatephase.Value = "July" Or Me.cmbdatephase.Value = "August" Or Me.cmbdatephase.Value = "September" Or Me.cmbdatephase.Value = "October" Or Me.cmbdatephase.Value = "November" Or Me.cmbdatephase.Value = "December" Then

cmbowners.Value = "Select Owner"
For X = 1 To cmbowners.ListCount
cmbowners.RemoveItem (cmbowners.ListCount - 1)
Next X
cmbowners.AddItem ("Select Owner")


Set cnn = CurrentProject.Connection
strSQL = "Select distinct txtidowner FROM SAPLOG WHERE initialreviewphase='" & cmbdatephase.Value & "' AND expire=0"

Set rs = cnn.Execute(strSQL)

rs.MoveFirst

Do While Not rs.EOF

strVAR = rs.Fields(0).Value



rs.MoveNext

cmbowners.AddItem Chr(34) & strVAR & Chr(34)

Loop
rs.Close

Set rs = Nothing
Set cnn = Nothing
MsgBox "ID Owners retreived for reivew month: " & cmbdatephase.Value & ". Please select ID Owner from list and click send email reports button."
cmbdatephase.Locked = True
Else
MsgBox "Please select a Month to review."
End If
 
You may try something like this:
...
Set rs = cnn.Execute(strSQL)
If rs.BOF Or es.EOF Then
MsgBox "No record found"
Exit Sub
End If
rs.MoveFirst
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top