View Full Version : Multiple Criteria opening multiple forms


Laocon
09-04-2001, 01:25 AM
Hi all,

I have two combo boxes - one which filters the record source for the second - and a button on a form.

I'm using this code on the OnClick of the button, but it doesn't work - I get a 'Type mismatch' error:

Private Sub Command5_Click()
On Error GoTo Err_Command5_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "DEF_Forecast MF"
DoCmd.OpenForm stDocName, , , ("[CompanyID]=" & Me![CompanyID] And "[PeriodID]=" & Me![PeriodID])

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

End Sub

Anyway, assuming I can get over this hurdle, I want to move onto the second hurdle...

I actually want to open 3 copies of DEF_Forecast MF. One for [PeriodID], One for [PeriodID]+1 and one for [PeriodID]+2.

I want these to be opened at the same time, after pressing the button, so that the user must fill out the subform of [PeriodID], then after closing this form, the user must fill out the subform of [PeriodID]+1, after closing and then [PeriodID]+2 ... I realise therefore that you actually need to open them in reverse order so that [PeriodID] is opened last and filled in first...

Sounds simple - but I just can't do it! BTW I am not good with code...

Laocon
09-04-2001, 11:18 PM
Does anyone have a suggestion??

If not like this, a work-around?

Alexandre
09-05-2001, 12:46 AM
Try:
DoCmd.OpenForm stDocName, , , ("[CompanyID]= " & Me![CompanyID] & " And [PeriodID]= " & Me![PeriodID]).

Note that this assumes tha both CompanyID and PeriodID are numeric fields. Syntaxt for text fields would be:
DoCmd.OpenForm stDocName, , , ("[CompanyID]= '" & Me![CompanyID] &"'"
etc.
And eventually a routine handling the case when the string value contains: '

Alex

Alexandre
09-05-2001, 01:26 AM
Regarding the second point, if the user must fill forms in a certain order, don t let him/her the choice at all. Moreover, the less forms you open at the same time, the better it is for the clarity of the interface, memory management and record locking issues if the forms are used for updating values from the same table.

Assuming that the 3 forms you are talking about are only used in this context, I would propose to open the first form from the on click event of your button, then successively open the following one, from the on close event of the previous: User closes Form1 and opens Form2.. You can open each form on the right record with:


Private Sub Form1_Close()
DoCmd.OpenForm "Form2", , ,"PeriodID= " & (Me.[PeriodID]+1)

End Sub


With a few more efforts you could probably use the same report and programatically switch from on record to the following once the user have clicked on a validation button (by using the bookmark or changing on the fly the form filter property for example). The result would be much cleaner.

Alex

[This message has been edited by Alexandre (edited 09-05-2001).]

[This message has been edited by Alexandre (edited 09-05-2001).]

Laocon
09-05-2001, 09:42 AM
TY

Two great answers http://www.access-programmers.co.uk/ubb/smile.gif