How to create a generic code
I must write 7 functions containing one and the same sql query depending on the choice
made in the basic table(FOrderIndformation).
The code that i must repeat 7 times, in each of the 7 function is the following:
Dim afid As String
Dim strDocName As String
strDocName = “FOrderinformation”
If IsOpen(strDocName) = True Then
Dim office As Control
Set office = Forms![FOrderInformation]![office]
Dim SQLLondon As String
dim sqlBerlin as string
SQLLondon = “AND ((Customers.afid)=1)”
SQLBerlin = “AND ((Customers.afid)=2)”
If office = 1 Then
afid = SQLLondon
ElseIf office = 2 Then
afid = SQLBerlin
end if
The above coding gives me the string afid, which i concatenate with the basic sql
called by me SQLBas, for example:
Dim SQLCustomerOrder As String
Dim SQLBas As String
SQLBas = ( a valid sql query)
SQLCustomerOrder = SQLBas & afid
Forms!frmCustomerOrders.RecordSource = SQLCustomerOrder
I have 6 more similar functions.My question is how to spare time and space
and eliminate writing one and the same code to define the the sql which i call afid?