Update subform based on main form combo box

Hedge01

New member
Local time
Tomorrow, 08:52
Joined
Dec 18, 2021
Messages
8
Hi hoping someone can help.

I have a main form with a combo box on the main form with 3 options Shanghai, Ningbo, Qingdao
A sub form with a combo box from an imbedded query with multiple columns Vessel, Voyage, ETA, ETDShanghai(Column3) , ETDNingbo(Column4), ETDQingdao(Column5). These date fields have different dates based on the vessel and voyage selected.

If shanghai is selected on the main form the ETD field in the subform should be the ETDShangai Value as being column(3).

Lines for Voyage and ETA work correctly. The last 3 lines i need help!

Private Sub VesselName_AfterUpdate()
Me.Voyage = Me.VesselName.Column(1)
Me.ETA = Me.VesselName.Column(2)
Parent.OriginPort. "Shanghai" Then Me.ETD = Me.VesselName.Column(3)
Else
Parent.OriginPort. "Ningbo" Then Me.ETD = Me.VesselName.Column(4)
Else
Parent.OriginPort. "Qingdao" Then Me ETD = Me.VesselName.Column(5)

End Sub
 
There is no If Then to go with the Else. And there can be only one Else.

If ... Then
...
ElseIf ...
...
ElseIf ...
'''
Else
...
End If

But maybe Select Case structure would be better.

Code:
Select Case Me.Parent.OriginPort
   Case "Shanghai"
        Me.ETD = Me.VesselName.Column(3)
   Case "Ningbo"
        Me.ETD = Me.VesselName.Column(4)
   Case "Qingdo"
        Me.ETD = Me.VesselName.Column(5)
End Select
 
Last edited:
Thanks so much, really appreciate the help.
 
Here's another variation:
Code:
Dim x As Integer
With Me
x = Switch(.Parent.OriginPort = "Shanghai", 3, .Parent.OriginPort = "Ningbo", 4, .Parent.OriginPort = "Qingbo", 5)
.ETD = .VesselName.Column(x)
End With
 

Users who are viewing this thread

Back
Top Bottom