hi, ive adapted this code to fit my application and it works. Any ideas on how i could make this into a global module so it can be reused through out application?
ive tried the following but i get an error if i try to assign a null value to a string? are their any ways round this?
Form code
Private Sub chkEmployee_Click()
Dim single_field As String
Dim many_fields As String
'' set up the string values
strFirst = Me.Parent.FirstName
strLast = Me.Parent.LastName
strCompany = Me.Parent.Company
single_field = ""
'' pass the values to the generic string
strUpdate_one = strFirst
strUpdate_two = strLast
strUpdate_three = strCompany
'' finally set up a string to hold field name
strField_one = " first name"
strField_two = " last name"
strField_three = " company"
'' code starts here___________________________________________
If chkEmployee.Value = True Then
Call Global_update(strUpdate_one, strUpdate_two, strUpdate_three, strField_one, strField_two, strField_three)
Else
'' build a message box saying which fields are filled in
MsgBox "you have successfully updated employee section"
End If
End Sub
Global code
Public Sub Global_update(strUpdate_one As String, strUpdate_two As String, strUpdate_three As String, strField_one As String, strField_two As String, strField_three As String)
single_field = ""
If Nz(strUpdate_one) = "" Then
single_field = strField_one
many_fields = strField_one
End If
If Nz(strUpdate_two) = "" Then
If single_field = "" Then
single_field = strField_two
Else
single_field = single_field & ", " & strField_two
End If
many_fields = strField_two
End If
If Nz(strUpdate_three) = "" Then
If single_field = "" Then
single_field = strField_three
Else
single_field = single_field & ", " & strField_three
End If
many_fields = strField_three
End If
If single_field <> "" Then
MsgBox "You need to complete the following: " & single_field & " fields"
Cancel = True
''Me.Controls(many_fields).SetFocus
End If
End Sub