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!

IF Statement Based on Returned Records

Status
Not open for further replies.

MagnusFox

IS-IT--Management
Jan 12, 2001
51
US
I have a form that has a button that on click runs a select query. The query results pop up in a new window.

Now I want to modify the button so that when the query runs and the query has results, it updates a field in my form. I also do not want the query results to display on the screen. All I want is to press the button and know if any data is returned in the query, then update a field.

Here is some code that logically does what I want, but does not really work:

If (DoCmd.OpenQuery(stDocName, acNormal, acEdit) = True) Then
Forms!Form1.[Field1] = 99
End If

I looked at the ReturnsRecords = TRUE code, but I do not understand how to use it.

Many Thanks
 
What it sounds like is you want to know how many records are returned by your query and then put then a a control. You can do this with the DCount function like so:

ControlToUpdate = DCount("[UniqueID]","MyQueryName")

That should do it if I'm understanding you correctly.

HTH Joe Miller
joe.miller@flotech.net
 
Just wanted you to know that it works. Many thanks Joe, you have helped me on many questions!

Here is what I did:

Dim ReturnedRecords As Integer

ReturnedRecords = DCount("[Unique ID]", "MyQueryName")
If (ReturnedRecords > 0) Then
Forms!Form1.[Field1] = 99
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top