Solved Totally baffled (1 Viewer)

Sam Summers

Registered User.
Local time
Today, 21:16
Joined
Sep 17, 2001
Messages
939
Hi, here i am again.

I have a form (ViewVessel) with a tabbed form on it with a subform on one of the tabs (MaintenanceSubform).

On the 'MaintenanceSubform' i have a combobox control 'Status' whose RowSource is a table 'Status'.
Column(0) is the primary key and there are three items in the table from 1 to 3 (In Service; Out of Service; Awaiting Parts).
Column Count = 3, Column widths = 0cm;0cm;4cm
Bound Column = 1
When the user selects one of these items, if it is In Service (1) then 'ViewVessel' Textbox 'NewStatus' is updated.

If they select Out of Service (2) or Awaiting Parts (3) this code should be run:

Code:
Private Sub Status_AfterUpdate()

    Dim strTo As String
    Dim strMessage As String
    Dim strSubject As String
    Dim attch As String
    Dim lngWhite As Long
    Dim strText As String
    Dim Cvessel As String
   
    DoCmd.OpenQuery "RecordMaintenanceQry"
'    Forms![ViewVessel].Requery
'    Forms![ViewVessel]![MaintenanceSubform].Requery
'    Forms![MainPanel].Requery
   
    If Me.Status.Column(0) = "2" Or "3" Then
   
  '  Forms![MainPanel].Requery

        strTo = "xxxxxxxxxxxxxxx.com"
        strSubject = "Outage Report. "
       
        Forms!ViewVessel.VesselName.SetFocus
        Cvessel = Forms![ViewVessel]![VesselName].Text
        strText = " has just been reported as out of service"
        strMessage = Cvessel & strText

        Call SendEmailWithOutlook(strTo, strSubject, strMessage, attch)
        DoCmd.RunCommand acCmdSaveRecord

    Else
       
    End If

End Sub

However when i run it after selecting 'In Service' (1) it still runs the code?
When i break it and hover over line 16 (If Me.Status.Column(0) = "2" Or "3" Then) i can see that 1 is indicated?

Also continuing on in the code it breaks at this line - Forms!ViewVessel.VesselName.SetFocus. sayng that it cannot set the focus?

I am totally baffled by this and have tried it in the BeforeUpdate Event as well but it still doesnt do anything apart from send me emails.

I would be very grateful if someone can assist with my obvious stupidity..........
 

bastanu

AWF VIP
Local time
Today, 14:16
Joined
Apr 13, 2010
Messages
1,401
Can you show the Status table? It should only have two fields: StatusID -PK, autonumber and Status - Short Text (In Service, Out of service, Awaiting Parts). Now your combo should only have two columns not three with the widths of 0;4.
And in the code you need to remove the double-quotes surrounding the values as the combo's bound value is a number not text:
If Me.Status = 2 Or Me.Status = 3 Then
Cheers,
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:16
Joined
Feb 28, 2001
Messages
27,001
Vlad's second point (about how you write the IF test) is important. The expression "2" OR "3" is ALWAYS TRUE (in the Boolean sense) because at least some bits are set for both the character "2" and the character "3" - which is what you wrote. That OR as written is a logical operator between two operands, which makes it a Boolean sub-expression. If Me.Status.Column(0) is not 0, it is ALSO TRUE (in the Boolean sense) because only a 0 is FALSE. Which means, when you reduce the expression, you are asking if TRUE = TRUE - which is TRUE.
 

Sam Summers

Registered User.
Local time
Today, 21:16
Joined
Sep 17, 2001
Messages
939
Hi Guys,

Thank you both for your help and advice which is gratefully received.

I implemented Vlad's input and it appears to be working now
 

Users who are viewing this thread

Top Bottom