How to Stop OpenArg code when field is already populated

jom1918

Registered User.
Local time
Tomorrow, 05:02
Joined
Apr 26, 2011
Messages
30
I have an order form that auto-populates details from the customer table into adderss and contact controls. But I don't want it to auto-populate when the underlying order table already has data in the related fields. I am a complete novice so I am sure the answer will eb simple. Here is the code I use on Load form event...
======
Private Sub Form_Load()
'Use this version if the ID is a number
Dim x As Variant
Dim strControl As String
Dim lngID As Long
'If parameters exist, use them
If Len(Me.OpenArgs) > 0 Then
'Split creates a zero-based array from the input string
x = Split(Me.OpenArgs, "|")
strControl = x(0)
lngID = x(1)
Me(strControl) = lngID
End If

Me.Ship_Contact = Me.CustiDcbo.Column(2) + " " + Me.CustiDcbo.Column(3)
Me.Ship_Tel = Me.CustiDcbo.Column(8)
Me.Ship_Addressee = Me.CustiDcbo.Column(1)
Me.Ship_Address = Me.CustiDcbo.Column(4)
Me.Ship_Suburb = Me.CustiDcbo.Column(5)
Me.Ship_State = Me.CustiDcbo.Column(6)
Me.Ship_PCode = Me.CustiDcbo.Column(7)
Me.Ship_Country = Me.CustiDcbo.Column(15)
Me.Order_Contact = Me.CustiDcbo.Column(2) + " " + Me.CustiDcbo.Column(3)
Me.Order_Cell = Me.CustiDcbo.Column(8)
Me.Order_Email = Me.CustiDcbo.Column(9)
Me.Bill_Address = Me.CustiDcbo.Column(10)
Me.Bill_Suburb = Me.CustiDcbo.Column(11)
Me.Bill_State = Me.CustiDcbo.Column(12)
Me.Bill_PCode = Me.CustiDcbo.Column(13)
Me.Bill_Country = Me.CustiDcbo.Column(14)
Me.DelZone = Ship_PCode.Column(1)
Me.ShipMethod = Ship_PCode.Column(2)
Me.ShipVia = Ship_PCode.Column(3)

End Sub
======
 
Consider this code . . .
Code:
Private Sub Form_Load()
    Dim args
[COLOR="Green"]    'If parameters exist, use them[/COLOR]
    If Len(Me.OpenArgs) > 0 Then
        args = Split(Me.OpenArgs, "|")
[COLOR="Green"]        'args(0) is control name, args(1) is control value[/COLOR]
        Me(args(0)) = args(1)
    End If
    SetDataFromCombo

End Sub

Private Function WillSetDataFromCombo() As Boolean
[COLOR="Green"]'   perform logic here to determine if update from combo should occur[/COLOR]
    WillSetDataFromCombo = False
End Function

Private Sub SetDataFromCombo()
    If WillSetDataFromCombo Then
        Me.Ship_Contact = Me.CustiDcbo.Column(2) + " " + Me.CustiDcbo.Column(3)
        Me.Ship_Tel = Me.CustiDcbo.Column(8)
        Me.Ship_Addressee = Me.CustiDcbo.Column(1)
        Me.Ship_Address = Me.CustiDcbo.Column(4)
[COLOR="Green"]        'and so on, and so on[/COLOR]
    End If
End Sub
I would not assign that data from the combo to the form in all cases. Write a function, in this case "WillSetDataFromCombo" to determine if the update should occur, so check your underlying table for data, and if it's not present, then return True, and it's obvious what should happen if WillSetDataFromCombo is True.

And now other code can do this update too, if needs be, by just calling SetDataFromCombo. That routine checks whether it is allowed to run, if so, it does.

Makes sense?
 
Thanks lagbolt. I think I understand. I will give it a try and let you know how I go. Really appreciate your help and quick response.
 

Users who are viewing this thread

Back
Top Bottom