code for checking control

geoffreyp

Registered User.
Local time
Today, 23:26
Joined
Nov 27, 2009
Messages
13
Scenario:
I have a form that 1. USER makes a selection & 2 based on that selection(using a option group) a report is generated.
I have used code to make the 2nd bit occur but the i want to cover the scenario when a user DOESNT make the first selection but makes the second selection and gets an access message(whch some users might freak about).
So what i want to check is, when the control to make the first selection, has not been used ie. when it is mt. but i am not sure where to start with this.
As i have only just started using code, please excuse the methodology displayed and i would welcome any suggestions as how to tidy it up(Like nesting statements etc) although currently this little routine is working quite nicely, but you know, we forever fiddle to tidy things up.
see current code below

Private Sub PreviewOptionGp_Click()
Dim DocName1 As String
Dim DocName2 As String
Dim DocName3 As String

DocName1 = "rCatalogue"
DocName2 = "rGalleryLabels"
DocName3 = "fPreview_Cat_Labels"

'(in here i need a routine to check if the control "ExhibitionName" is mt)


If Me.PreviewOptionGp = 1 Then
DoCmd.OpenReport DocName2, acViewPreview, , "ExhibitionName=" & ExhibitionSelect
DoCmd.Close (acForm), DocName3

Else

If Me.PreviewOptionGp = 2 Then
DoCmd.OpenReport DocName1, acViewPreview, , "ExhibitionName=" & ExhibitionSelect
DoCmd.Close acForm, DocName3

Else

If Me.PreviewOptionGp = 3 Then
DoCmd.CancelEvent
DoCmd.Close (acForm), DocName3

End If
End If
End If


End Sub
 
Hi Adam, sorry not sure what you mean. How should i post code that i have used?
 
not sure what you mean adam, sorry, can you possibly elaborate?
 
It isn't clear what you're asking for.

As far as tidying up the code, that's what Adam was talking about. You need to indent your code so we can read it.

A couple of things:
1. You can replace all those If...else statements with a Case statement.
2. If you want to use If...else if...else if, you should consider using ElseIf.
3. I don't understand what "mt" is. In the stuff I do, it stands for "main tank". What are you trying to do with "mt"?
4. Indent your code so we can read it! I'm way too lazy to sort through all that stuff and answer a question. I usually spend about 15 seconds max reading a question before I decide to answer it. If you haven't captured my attention in 15 seconds, I'm gone. Many here are like me.
5. Make it clear what your question is. I don't know what you want.
 
I have made some modifications to your code:

Private Sub PreviewOptionGp_Click()
Dim DocName1 As String
Dim DocName2 As String
Dim DocName3 As String

DocName1 = "rCatalogue"
DocName2 = "rGalleryLabels"
DocName3 = "fPreview_Cat_Labels"

'(in here i need a routine to check if the control "ExhibitionName" is mt)
'This is code to check the "ExhibitionName" control
'You did not say what type of control this is and what type of value it 'returns, so ...
'if it is a combo box that returns a numeric value (as in a PrimaryKey 'value ) uncomment the line below:
'If me.ExhibitionName > 0 then

'from your post I am assuming that you are using a combo box and it is 'returning a string value so use:
If not isnull(me.ExhibitionName) then

Select Case Me.PreviewOptionGp
Case 1
DoCmd.OpenReport DocName2, acViewPreview, ExhibitionName=" & ExhibitionSelect
DoCmd.Close (acForm), DocName3

Case 2
DoCmd.OpenReport DocName1, acViewPreview, , ExhibitionName=" & ExhibitionSelect
DoCmd.Close acForm, DocName

Case 3
DoCmd.CancelEvent
DoCmd.Close (acForm), DocName3

End Select
End If
End Sub

If I understood what you wanted to do, the code above should work. Watch out for word wrapping from the code being posted here.
 
Thanks Mr B, that has given me heaps to work with and many thanks for "tidying up" my attempts at code.

Geoff
 

Users who are viewing this thread

Back
Top Bottom