Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Is there an easier way to get my data


Reply
 
Thread Tools Display Modes
  #1  
Old 07-20-2006, 12:23 PM
Chris Allen's Avatar
Chris Allen Chris Allen is offline
Centurion
 
Join Date: Jul 2005
Posts: 167
Default Is there an easier way to get my data


Hi All,

I have been working on this app for about a year now, lots of data to store and so on.

Everything in my code (below) works with no errors at all. but the way I am doing it is a pain.
If its easy enough for some one to modify this code to simplify, may be using sql join syntax or the like I could use the help, or even UDT. This is really getting old.

And Yes, I am trying to get ADO but its taking some time.

What this is doing is this:
I put a 7 digit(charactor i.e. 0605008) in a text box. it searches for that number(Text) in the column of the db and returns the data. As I said it works fine. But I have to keep doing this is various places in stead of just one.

Code:
Code:
Private Sub txtJob_KeyUp(KeyCode As Integer, Shift As Integer) '<EhHeader> On Error GoTo txtJob_KeyUp_Err '</EhHeader> Dim DBB As Database Dim CusRST As Recordset Dim GenRS As Recordset 'Clears Job Number textbox and all data text boxes if 'F2' Key is pressed then exits If KeyCode = vbKeyF2 Then Dim oCTL As Control Dim oTXT As TextBox For Each oCTL In Me.Controls If TypeOf oCTL Is TextBox Then Set oTXT = oCTL oTXT.Text = "" End If Next Set oTXT = Nothing Exit Sub End If 'If 'Enter' key is pressed and a valid job number is 'entered this retrieves all job related data If KeyCode = 13 Then Set DBB = OpenDatabase(App.Path & "\custdb.mdb") If Len(txtJob.Text) = 7 Then Let CurJobNumber = txtJob.Text Set CusRST = DBB.OpenRecordset("Customers") Set GenRS = DBB.OpenRecordset("Generators") If GenRS.RecordCount <= 0 Then CusRST.Close GenRS.Close DBB.Close Set CusRST = Nothing Set GenRS = Nothing Exit Sub End If With GenRS 'Generator Recordset .Index = "genjobnum" .Seek "=", Trim$(txtJob.Text) If GenRS.NoMatch Then MsgBox "The job number you entered is not valid. Please re-check you job number and try agian.", vbInformation, "Job Invalid" txtJob.Text = "" txtJob.SetFocus Exit Sub End If With CusRST 'Customer Recordset .Index = "CustomerID" .Seek "=", GenRS.Fields("CustomerID").Value '126 fraMain.Caption = txtJob.Text & ": " & cusrst.Fields("Companyname").Value CustInfo(0).Text = CusRST.Fields("Companyname").Value 'Customer Name CustInfo(1).Text = CusRST.Fields("address").Value 'Project ID CustInfo(2).Text = CusRST.Fields("city").Value '& ", " & GenRS.Fields("GenFName").Value ' & vbCrLf & GenRS.Fields("Genaddress").Value & vbCrLf & GenRS.Fields("gencity").Value & ", " & GenRS.Fields("genstate").Value CustInfo(3).Text = CusRST.Fields("state").Value CustInfo(4).Text = Format$(CusRST.Fields("phone").Value, "(###)###-####") CustInfo(5).Text = Format$(CusRST.Fields("fax").Value, "(###)###-####") CustInfo(6).Text = CusRST.Fields("accountnum").Value If CusRST.Fields("accttype").Value = "ACTIVE" Then AcctType(0).Value = True Else AcctType(1).Value = True End If GenInfo(0).Text = IIf(IsNull(GenRS.Fields("GenFName").Value), GenRS.Fields("GenlName").Value, GenRS.Fields("GenlName").Value & ", " & GenRS.Fields("GenFName").Value) GenInfo(1).Text = GenRS.Fields("genaddress").Value 'Project ID GenInfo(2).Text = GenRS.Fields("gencity").Value '& ", " & GenRS.Fields("GenFName").Value ' & vbCrLf & GenRS.Fields("Genaddress").Value & vbCrLf & GenRS.Fields("gencity").Value & ", " & GenRS.Fields("genstate").Value GenInfo(3).Text = GenRS.Fields("Genstate").Value GenInfo(4).Text = GenRS.Fields("gencounty").Value GenInfo(5).Text = GenRS.Fields("municipaltownship").Value GenInfo(6).Text = Format$(GenRS.Fields("esttonnage").Value, "###,###.#0") GenInfo(7).Text = Format$(GenRS.Fields("tonsapp").Value, "###,###.#0") GenInfo(8).Text = Format$(GenRS.Fields("ytdtotal").Value, "###,###.#0") GenInfo(9).Text = Format$(GenRS.Fields("tphresult").Value, "###,###") GenInfo(10).Text = Format$(GenRS.Fields("tphlast").Value, "###,###") GenInfo(11).Text = IIf(IsNull(GenRS.Fields("tphsub").Value), "None", GenRS.Fields("tphsub").Value) GenInfo(12).Text = IIf(IsNull(GenRS.Fields("wcsub").Value), "None", GenRS.Fields("wcsub").Value) GenInfo(13).Text = IIf(IsNull(GenRS.Fields("wasteclass").Value), "None", GenRS.Fields("wasteclass").Value) GenInfo(14).Text = IIf(IsNull(GenRS.Fields("wasteclassrcvddate").Value), "N/A", GenRS.Fields("wasteclassrcvddate").Value) GenInfo(15).Text = IIf(IsNull(GenRS.Fields("waiver").Value), "None", GenRS.Fields("waiver").Value) GenInfo(16).Text = IIf(IsNull(GenRS.Fields("sampledate").Value), "None", GenRS.Fields("sampledate").Value) GenInfo(17).Text = IIf(IsNull(GenRS.Fields("expiredate").Value), "None", GenRS.Fields("expiredate").Value) End With End With GenRS.Close CusRST.Close DBB.Close Set DBB = Nothing End If End If '<EhFooter> Exit Sub txtJob_KeyUp_Err: MsgBox Err.Description & vbCrLf & "in SoilExpress.Form2.txtJob_KeyUp " & "at line " & Erl '</EhFooter> End Sub

Last edited by 00100b; 07-20-2006 at 12:28 PM. Reason: Added VB/Code Tags
Reply With Quote
  #2  
Old 07-21-2006, 01:24 AM
TRANSLTR's Avatar
TRANSLTR TRANSLTR is offline
Centurion
 
Join Date: Aug 2005
Location: UK
Posts: 153
Default

There's no quick answer to this. If I was doing it, I would have a "Customer" class with a "GetCustomer" method on it. Create yourself a customer object when you load your form.

Have you ever used the VB6 class bulder utility? It's useful for this kind of thing.

Also - see if you can get hold of Rockford Lhotka's "VB6 Business Objects". Though it's harder to find these days.

Shout if you want a hand.
__________________
Leveraging synergies to deliver outstanding customer value. And all that stuff.
Reply With Quote
  #3  
Old 07-21-2006, 01:46 AM
webbone's Avatar
webbone webbone is offline
Hydrogen Powered

Administrator
* Expert *
 
Join Date: Jul 2003
Location: Sacramento, CA
Posts: 6,090
Default

Definitely using ADO and the appropriate SQL query would help you out. For more on ADO see the ADO Tutorial here on the forum (in case you haven't already).

Your SQL construction would be done something like this:

Code:
Dim sSQL as String sSQL = "SELECT * FROM Generators WHERE genjobnum = " & Trim$(txtJob.Text) 'now use sSQL to open your recordset

For more on SQL see SQL Tutorial
__________________
"With the appearance of the AddressOf operator, an entire industry has developed among authors illustrating how to do previously impossible tasks using Visual Basic. Another industry is rapidly developing among consultants helping users who have gotten into trouble attempting these tasks." -Dan Appleman
Reply With Quote
  #4  
Old 07-22-2006, 03:55 AM
Chris Allen's Avatar
Chris Allen Chris Allen is offline
Centurion
 
Join Date: Jul 2005
Posts: 167
Default

Well, I have axTools, Code Smart 2007 for vb6 (awesome product) it has all that and the some. Never had much luck with classes but will give it a go.

thanks
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->