Does someone know what i'm doing wrong?

Arcadia

Registered User.
Local time
Today, 10:31
Joined
Jan 25, 2013
Messages
66
I try to run this code but it doesn't show me the right result..
I tried hours to fix it but my brain cells are slowly getting tired :banghead:
help me :o


Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Me.Training_label.Visible = False
If Field1 = "Training" Then
Me.Training_label.Visible = True

Me.Amsterdam_Label.Visible = False
If Field1 = "Amsterdam" Then
Me.Amsterdam_Label.Visible = True
End If
End Sub
 
Is this what you are trying to do?
Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    If Field1 = "Training" Then
        Me.Training_label.Visible = True
        Me.Amsterdam_Label.Visible = False
    ElseIf Field1 = "Amsterdam" Then
        Me.Training_label.Visible = False
        Me.Amsterdam_Label.Visible = True
    End If
End Sub
 
Is this what you are trying to do?
Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    If Field1 = "Training" Then
        Me.Training_label.Visible = True
        Me.Amsterdam_Label.Visible = False
    ElseIf Field1 = "Amsterdam" Then
        Me.Training_label.Visible = False
        Me.Amsterdam_Label.Visible = True
    End If
End Sub


ehm no.. i still get the same result.

I got this code earlier to work but i forgot.. :(
 
Like eugin said, we need to know what you're trying to accomplish before we can suggest a solution. However, a more general tip would be to format your code a little better. It makes it easier for others to read and makes it easier for you to keep track of everything that's happening. For example, always use an "End If" to close your if statements. That way you can be 100% sure that you're doing everything you want to inside of that If statement. For example...

Code:
If Not IsNull(myControl.Value) Then
    'your code goes here...
    'and here.
End If

'Things that happen regardless of the condition happen here.

It seems to me like you're either having too much or too little happening inside of your if statement. That's why we need to know what you're trying to accomplish before we can help.
 
Well in Field1 i made different labels..

For example:

Field1
text1

Field1
Text2


Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Me.text1_label.Visible = False
If Field1 = "text1" Then
Me.text1_label.Visible = True


Me.text2_Label.Visible = False
If Field1 = "text2" Then
Me.text2_Label.Visible = True

End If
End If
End Sub


So with the if the label has the caption text1 than it must show the info of text1

and the text2_Label has to show the info with the caption text2 and so on..
 
Okay, I think I understand what you're trying to do. If I'm reading that correctly, you just want the textboxes for each field to be visible if the text equals a certain value, right? If that's right, then the if statements should be independent of each other. The way you have it written, it checks the text in Field1, then if it equals "text1", it checks Field2 as well.

You may want to get into the habit of indenting when you enter a new loop/conditional statement. It makes things a lot easier for you and others who have to read your code. Anyway, I think what you want is...

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

Me.text1_label.Visible = False
If Field1 = "text1" Then
     Me.text1_label.Visible = True
End If

Me.text2_Label.Visible = False
If Field1 = "text2" Then
     Me.text2_Label.Visible = True
End If

End Sub
 
Complicated IF statements can get dicey, especially when toggling and using a text string. The sample below may prove useful in that both fields are made invisible and only become visible when a specific condition is met.

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    Me.Training_label.Visible = False
    Me.Amsterdam_Label.Visible = False
    if Field1 = "Training" Then  Me.Training_label.Visible = True
    If Field1 = "Amsterdam" Then Me.Amsterdam_Label.Visible = True
End Sub

--------------------------------------------------------------------
To minimize string errors, use the ucase and trim functions.

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    Me.Training_label.Visible = False
    Me.Amsterdam_Label.Visible = False
    if trim(ucase(Field1)) = ucase("Training") Then  Me.Training_label.Visible = True
    If trim(ucase(Field1)) = ucase("Amsterdam") Then Me.Amsterdam_Label.Visible = True
End Sub
 

Users who are viewing this thread

Back
Top Bottom