Results 1 to 2 of 2

Thread: generic code

  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    generic code

    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?

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: generic code

    Put that code in a function, like this:

    <pre>Public Function Getafid() as String
    Dim strDocName As String
    strDocName = "FOrderinformation"
    If IsOpen(strDocName) = True Then
    Dim office As Control
    Set office = Forms![FOrderInformation]![office]
    If office = 1 Then
    Getafid = "AND ((Customers.afid)=1)"
    ElseIf office = 2 Then
    Getafid = "AND ((Customers.afid)=2)"
    End If
    End If
    End Function

    Then you can do this:

    [pre]
    Dim SQLCustomerOrder As String
    Dim SQLBas As String
    SQLBas = ( a valid sql query)
    SQLCustomerOrder = SQLBas & Getafid()
    </pre>

    Legare Coleman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •