Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving code from VBA to MySQL

Status
Not open for further replies.

galorin

MIS
Nov 22, 2007
154
GB
I have the following bit of VBA code in an MSAccessDB. It is a frontend to a MySQL database, and does no storage on it's own as I don't trust Access. We are automatically generating a design production number based on information stored in the database, but munged together by VBA. Anyhow, here's the code:

Code:
SQLout = "SELECT h.ht_id, h.softver, h.House_type"
SQLout = SQLout & " , b.ShortCode AS builder_ShortCode"
SQLout = SQLout & " , q.design_level"
SQLout = SQLout & " , h.Floor"
SQLout = SQLout & " , h.Revision"
SQLout = SQLout & " , d.ShortCode AS dist_ShortCode"
SQLout = SQLout & " FROM HouseType AS h"
SQLout = SQLout & " INNER JOIN quotations as q on q.quote_id = h.quote_id"
SQLout = SQLout & " INNER JOIN CompShort as b ON b.Comp_ID = q.build_id"
SQLout = SQLout & " INNER JOIN CompShort as d ON d.Comp_ID = q.dist_id"
SQLout = SQLout & " WHERE h.quote_id = " & Me.se
SQLout = SQLout & " and deleted = 0"
SQLout = SQLout & " ORDER BY House_Type"

Call connectDB
Call getData

If Not rst.EOF Then
        rst.MoveFirst
        Do
        'loop through resultset
        f(0) = rst.Fields(0)
        f(1) = rst.Fields(1)
        For I = rst.Fields.Count - 1 To 2 Step -1
         If IsNull(rst.Fields(I)) Then
          f(I) = ""
         ElseIf rst.Fields(I) = "non" Then
          f(I) = ""
         [i]ElseIf I = 6 Then [COLOR=green]'field where integer value of revision is kept[/color]
           If rst.Fields(I) = 0 Then
            f(I) = ""
           Else
            rev = rst.Fields(I)
            f(I) = "=rev-" & Chr(96 + rev) [COLOR=green]'Converts integer revision into a letter[/color]
           End If[/i]
        Else
        f(I) = "=" & rst.Fields(I)
        End If
        Next I
            field0 = rst.Fields(2)
            [COLOR=green]'field format is version=builder-region=level=housetype=floor=revision=distributor[/color]
            field1 = f(1) & f(3) & f(4) & f(2) & f(5) & f(6) & f(7)
            Me.ListPos.AddItem item:="" & f(0) & ";" & field1 & "" 
        rst.MoveNext
        Loop Until rst.EOF
    End If
cn.CLose

Probably not the cleanest code you've ever seen, but it does the job as best as I know how in VBA. I'd like to not only get this code out of VBA if possible, but be able to do it on the server, preferably as a view. I want to avoid writing this same code over again in the several reports I need to write, and also to make my code easier to manage.

I am thinking I will need to use something like concat(part1, "=", part2, "=") etc, but exclude the = if any values are null, or equal to non, and do the character conversion for the revision (italics above) Is this something that can be accomplished at the server level, rather than at application? If so, how?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top