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!

Barking up the right tree??(code help)

Status
Not open for further replies.

cram

Technical User
Nov 6, 2001
6
US
Hi all,
I'm working some code for the first time, and need a little backup here. I've got a form where I'd like to run a procedure after the user clicks a command button. The procedure checks two queries to see if the data entered meets two distinct criteria. The code craps out after opening the first query. Any help would be appreciated.
Thanks,
Cram



Sub tst()
Set db = CurrentDb()
Dim Criteria1 As Variant, Criteria2 As Variant
'Opens query for first criteria
DoCmd.OpenQuery "FLTUsed4", acViewNormal
DoCmd.GoToRecord acDataQuery, "FLTUsed4", acLast
Set Criteria1 = FLTUsed4.CountOfAuthor_Calc2.Value
If Criteria1 > 0 Then
DoCmd.Close acQuery, "FLTUsed4", acSaveNo
DoCmd.OpenForm "RefusalForm"
Else
DoCmd.Close acQuery, "FLTUsed4", acSaveNo
DoCmd.OpenQuery "LRQ3", acViewNormal
If LRQ3.CountofAuthorCalc2 > 0 Then
DoCmd.Close acQuery, "LRQ3", acSaveNo
DoCmd.OpenForm "RefusalForm2"
Else
DoCmd.Close acQuery, "LRQ3", acSaveNo
DoCmd.Close acForm, "PanelReservationForm", acSaveYes
DoCmd.OpenForm "ApprovalForm2"
End If
End If
End Sub
 
Saying it "craps out" isn't very helpful. What error message or other error indication are you getting? Rick Sprague
 
I think the problem is how you access the data the query returns. Load the queries in recordset objects. Something like this...

Sub tst()
Dim db as Database
dim rstQryA as recordset
dim rstQryB as recordset
Dim Criteria1 As Variant

Set db = CurrentDb()
set rstQryA=db.openrecordset("FLTUsed4")
rstQryA.MoveLast
Criteria1 = rstQryA!CountOfAuthor_Calc2
If Criteria1 > 0 Then
DoCmd.OpenForm "RefusalForm"
Else
set rstQryB=db.openrecordset("LRQ3")
rstQryB.MoveFirst
If rstQryB!CountofAuthorCalc2 > 0 Then
DoCmd.OpenForm "RefusalForm2"
Else
DoCmd.Close acForm, "PanelReservationForm", acSaveYes
DoCmd.OpenForm "ApprovalForm2"
End If
End If
End Sub

Hope this is of some help
Mangro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top