applying logic in form controls

P

Pitu

Still not working. Here is the code
Select Case Me.TriggerSource
Case Me.TriggerSource.Column(1) = "Other"
If Me.TriggerType.Column(1) = "Judgement" Then
Me.Text15 = "otherjudgement"
End If
Case Me.TriggerSource.Column(1) = "NCR"
If Me.TriggerType.Column(1) = "Judgement" Then
Me.Text15 = "ncrjudgement"
End If
Case Else
Me.Text15 = "hi"
End Select

the triggertype table is also set the same way as triggersource with id and
values. when i try to debug it. pointing cursor on Case
Me.TriggerSource.Column(1) = "Other" shows value "Other". If
Me.TriggerType.Column(1) = "Judgement" Then shows value of "Judgement" but
Me.Text15 = "otherjudgement" shows "hi". again Case
Me.TriggerSource.Column(1) = "NCR" shows value "Other" instead of "NCR" and
If Me.TriggerType.Column(1) = "Judgement" Then shows value "Judgement" and
Me.Text15 = "ncrjudgement" shows "hi" again.

Don't know now what is the problem. is it the problem with the if statement
or what?
 
R

Rob Oldfield

You've added in some things that aren't necessary. With a straight case
statement you don't need to add additional comparisons on the case lines.
So try this:

Select Case Me.TriggerSource.column(1) 'Note 1
Case "Other" 'Note 2
If Me.TriggerType.column(1) = "Judgement" Then
Me.Text15 = "otherjudgement"
End If
Case "NCR"
If Me.TriggerType.column(1) = "Judgement" Then
Me.Text15 = "ncrjudgement"
End If
Case Else
Me.Text15 = "hi"
End Select

1) You hadn't added the column part here, and that was the main reason it
wasn't working.
2) "Other" is autmatically compared to me.triggersource.column(1). That's
the way that straight Case statements work.
 
P

Pitu

now something really weird is happening. when i try to select the values say
"Other" and "Judgement" it still hows "hi" also trying to select "ncr" and
"judgement" still shows "hi" in the text box but when i close the form and
then again try to open it and go to the records saved on forms shows correct
answers on the textbox. so when I am doing the action the correct answer does
not show up but when I save the form and come back again the correct answers
comes up. does this have to do something since we have code in form current
event as well as TriggerSource_afterupdate event and TriggerType_Afterupdate
event?
 
R

Rob Oldfield

Do you have the code in a separate sub yet? It sounds like the versions in
the after update events of the combos is still failing (so when you change
one of the combos it's not using the correct code), but the version in the
current event of the form (which kicks in when you reopen the form or
navigate from record to record) is working.

If you think that you already do have that set up then could you try posting
all the code from the form please and I'll see if I can see what's wrong
with it.
 
P

Pitu

Here is all the code.

Option Compare Database
Private Sub SetText15()
Select Case Me.TriggerSource.Column(1)
Case "Other"
If Me.TriggerType.Column(1) = "Judgement" Then
Me.Text15 = "otherjudgement"
End If
Case "NCR"
If Me.TriggerType.Column(1) = "Judgement" Then
Me.Text15 = "ncrjudgement"
End If
Case Else
Me.Text15 = "hi"
End Select

End Sub

Private Sub Date_BeforeUpdate(Cancel As Integer)
If Not IsDate(Me.Date.Text) Then
MsgBox "Must have a Date in this box!"
Me.Undo ' Clear the textbox
Cancel = True ' Hold the cursor in this textbox
End If

End Sub



Private Sub Form_Current()
SetText15
End Sub

Private Sub TriggerSource_AfterUpdate()
SetText15
End Sub



Private Sub TriggerType_AfterUpdate()
SetText15
End Sub

'Private Sub Form_Current()
'Forms!triggervalidationaccessform!TriggerSrcDetail.Visible = "False"
'Forms!triggervalidationaccessform!ProblemDiscovered.Visible = "False"
'End Sub

'Private Sub TriggerSource_Change()
'Forms!triggervalidationaccessform!TriggerSource.SetFocus
'If Forms!triggervalidationaccessform!TriggerSource.Text = "Other" Then
'Forms!triggervalidationaccessform!TriggerSrcDetail.Visible = "True"
'Else
'Forms!triggervalidationaccessform!TriggerSrcDetail.Visible = "False"
'End If
'End Sub

'Private Sub TriggerType_Change()
'Forms!triggervalidationaccessform!TriggerType.SetFocus
'If Forms!triggervalidationaccessform!TriggerType.Text = "Judgement" Then
'Forms!triggervalidationaccessform!ProblemDiscovered.Visible = "True"
'Else
'Forms!triggervalidationaccessform!ProblemDiscovered.Visible = "False"
'End If
'End Sub




Note this also includes some other code that is commented on my form code
since I was trying that before. it is not used anymore. and the
date_beforeupdate is for other texbox that accepts date as value.
 
R

Rob Oldfield

Strange. As far as I can see that should be working. Would it be possible
for you mail me the file? Zip it up and send it to
oldfield then one of those strange @ things then hotmail.co.uk
 
R

Rob Oldfield

OK. I think we're probably there. Having taken a look at the db there's
one problem that is definitely causing it to go wrong and one thing that I
think might be confusing the issue.

The thing that is definitely causing it to go wrong...

.... is a little strange. Even though you have TriggerType_AfterUpdate
correctly set up in the code window, if you look at the properties of the
triggertype control then there's nothing displayed in it's after update
property. So you're updating it, but the code isn't firing. I don't know
how that would have happened but, to put it right, just retype an opening
square bracket into the after update property. That will expand out to
[Event Procedure] and it should be OK from there.

The thing that I think might be causing confusion....

If TriggerSource is Other, but TriggerType ISN'T Judgement, then the code
will hit nothing that sets Text15. So it might look as if the code isn't
running. I'd suggest, at least for testing, switching it to...

Private Sub SetText15()
Select Case Me.TriggerSource.Column(1)
Case "Other"
If Me.TriggerType.Column(1) = "Judgement" Then
Me.Text15 = "otherjudgement"
else
me.text15="Other other"
End If
Case "NCR"
If Me.TriggerType.Column(1) = "Judgement" Then
Me.Text15 = "ncrjudgement"
else
me.text15="Other NCR"
End If
Case Else
Me.Text15 = "hi"
End Select

How does that look?
 

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

Top