Global procedure instead of duplicate local procedures

Colman

Registered User.
Local time
Today, 06:13
Joined
Sep 5, 2011
Messages
37
I have a database comprising a number of different forms and each form has an identical text box "[scan input]" on it which is used for barcode scanner entries.

I currently have a duplicate block of code on each form, on the 'after update' property of the text box, which processes the bar code scans.

I would prefer to have a single global procedure which is called from all of the forms but just need to know how to set values on the forms. Obviously I can't refer to the form by name.

For instance, to clear the entry in the text box ready for the next barcode scan, in my local procedure I just use;

[scan input] = Null

My global procedure doesn't seem to like this.

Is there an easy way to do this?
 
You can pass the name of the form to the function as a string variable, then use that in the code, like:

Forms(VariableName).[scan input] = Null
 
You can just pass the Control reference, they are all unique:-

Code:
Private Sub scan_input_AfterUpdate()

    ProcessBarcode Me.[scan input]

End Sub


[color=green]' In a standard module:-[/color]
Public Sub ProcessBarcode(ByRef ctl As Control)

    With ctl
        [color=green]' Process
        ' the
        ' barcode[/color]
        
        .Value = Null
    End With
    
End Sub

Chris.
 
Thanks guys for both suggestions. I think both approaches will help me to move forward with improving the structure of my database.
 

Users who are viewing this thread

Back
Top Bottom