Close a previous form upon opening the next

WalterInOz

Registered User.
Local time
Tomorrow, 09:43
Joined
Apr 11, 2006
Messages
93
Can someone explain to me why the code below doesn't work? I think I'm doing everything right here. By clicking a button on frmFormsAndReports_period I open up the next form (frmBooks_Between_Dates),pass on the linkcriteria and then expect the first form to close. However, with the current code the first form blinks and stays on my screen, the second form doesn't open. When I remove the last 2 lines of the code opens up the next form but leaves the first form open. I don't get it, what's the problem. Is the first form closed to quickly for the criteria to be passed on?

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmBooks_Between_Dates"
DoCmd.OpenForm stDocName, , , stLinkCriteria

stDocName = "frmFormsAndReports_period"
DoCmd.close
 
I don't see where you are setting the stLinkCriteria to anything the next form can use. The stLinkCriteria is a WHERE clause for the next form without the word WHERE. It simply sets a filter for the next form when present. Having said that, try closing the current form with:
DoCmd.Close acForm, Me.Name, acSaveNo
 
RuralGuy said:
I don't see where you are setting the stLinkCriteria to anything the next form can use.

The way I have got this to work correctly is by basing the form on a query in which records are selected based on what I put in on the first form. Maybe that is not the best way to do it but is works fine. Should I leave the linkCriteria out of that line? Or use linkcriteria instead of my current solution?

Having said that, try closing the current form with:
DoCmd.Close acForm, Me.Name, acSaveNo[/QUOTE]

this works exactly as intended. Thanks RuralGuy
 
The current stLinkCriteria is a Null string and will not impact next form AND you are welcome.
 

Users who are viewing this thread

Back
Top Bottom