Trying to load a form predicated on 2 conditions (help w/ code!) :)

KelMcc

Rock n' Roll Paddy
Local time
Yesterday, 20:51
Joined
May 23, 2002
Messages
97
OK, I have a form, ISForms, that I'm really using as a switchboard. The form has to pieces of selectable criteria: BA & SRType. You select from combo boxes the criteria for each, then click the form you want and, based on your criteria, a specific form (SRType) that w/ the records of the appropriate BA.

I have it working so that if you select a BA, it takes you to the appropriate records. What I don't know how to do is make it pick a form (there are 2 choices) from the selection you make. More over, really, I'm talking about having the code think through 2 different ideas to give a form back to you.

This is my code so far that just gives me BA-specific records. I need the ability to add to also select a specific record. There are 4 choices in the SRType list box. 3 of which, N/A, All SR's, and SR should take you to "SR Form". The 4th choice, Project, should take you to the form "SR-Project Form".

Code thus far:
-----
Private Sub SREdit_Click()
On Error GoTo Err_SREdit_Click

Dim stDocName As String
Dim stLinkCriteria As String

If IsNull(Me.BA) Then
DoCmd.OpenForm "SR Form"
Exit Sub
End If

stDocName = "SR Form"

stLinkCriteria = "[BA]=" & "'" & Me![BA] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_SREdit_Click:
Exit Sub

Err_SREdit_Click:
MsgBox Err.Description
Resume Exit_SREdit_Click

End Sub
----
 
Private Sub SREdit_Click()
On Error GoTo Err_SREdit_Click

Dim stDocName As String
Dim stLinkCriteria As String

Select Case Me.[SRType]
Case "N/A","All SR's","SR"
stDocName="SR Form"
Case "Project"
stDocName="SR-Project Form"
End Select


If IsNull(Me.BA) Then
DoCmd.OpenForm stDocName
Exit Sub
End If

stLinkCriteria = "[BA]=" & "'" & Me![BA] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_SREdit_Click:
Exit Sub

Err_SREdit_Click:
MsgBox Err.Description
Resume Exit_SREdit_Click

End Sub
 
Travis, thanks! That worked like a charm. Kingsburg? Down by Fresno, yes?

I do have another "criteria" to add to this mix. I thought I'd described it in the original problem, but I realize after this worked so well, that I left this out... :( However, I'll try and see if I can learn from what you've shown me and figure it out myself first. :)

But, I do have a small follow up... "N/A", should actually load nothing, or should give a message, "not a valid option", or something like that. Basically, "N/A", means there are no valid forms for what you're asking.

To fix that would I just add something like this:
Case "N/A"
stDocName="ISForms"

ISForms is the form I'm using for the switchboard. So, I'm hoping this would just return them to this form?

If I can't figure out the bigger problem, I'll post that here. :)
 
Just seperate it as its own case, just as you describe. If this code is not on the "ISForm" then yes that would take you back. But if it is on the form just use "Exit Sub"

Select Case Me.[SRType]
Case "All SR's","SR"
stDocName="SR Form"
Case "Project"
stDocName="SR-Project Form"
Case "N/A"
stDocName="ISForm"
'Exit Sub 'This will end the running of the code.
End Select



PS. Yes you are correct it is about 20mi South of Fresno :^)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom