statement if vs select case

J

jean.ulrich

Hi

I am using the following script to open different forms

Private Sub Commande288_Click()

Dim stDocName As String
Dim stLinkCriteria As String

If Left([NoItem], 4) = "34-0" Then

stDocName = "34-0"

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

End If

If Left([NoItem], 4) = "41-0" Then

stDocName = "41-0"

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

End If

If Left([NoItem], 4) = "41-1" Then

stDocName = "41-1"

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

End If

If Left([NoItem], 4) = "51-0" Then

stDocName = "51-0"

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

End If
End Sub

The question is "what can i use (different code) to produce the same
thing ?
Should I use select case statement and if the answer is yes, how should
I proceed
Also, I would like to add a message box for all items that don't have a
related form
msgbox "There is no form for this kind of item"

thanks
 
S

strive4peace

Hi Jean,

here is the code you asked for

'~~~~~~~~~~~~~~~~~
Dim stDocName As String
Dim stLinkCriteria As String

SELECT CASE Left([NoItem], 4)
Case "34-0", "41-0", "41-1", "51-0"
stDocName = Left([NoItem], 4)
Case else
Msgbox "Invalid Item Number",,"Aborting"
Exit sub
END SELECT

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

but WHY are you opening different forms for different items??? Why not
just use one form and filter it?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top