Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 17th, 2006, 12:52 PM
Ausburgh Ausburgh is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 5 Ausburgh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 32 sec
Reputation Power: 0
VB 6.0 Connection to SQL Server Issues

HELP!!! New member here.

I'm running into a little bit of a problem ... I'm very new to VB 6.0 (learning as I go).

I was able to connect to our SQL server and I can write to the database via my application... however I CANNOT see the existing records (so I can't navigate, edit or delete the records). When I open the application it's blank.

Please help.

Here's my code:

Code:

Option Explicit
    Dim ABranch As String
    Dim ASal As Double
    Dim AAwd As Double
    Dim ABen As Double
    Dim AOT As Double
    Dim ATrav As Double
    Dim ATrans As Double
    Dim ATraining As Double
    Dim ARCU As Double
    Dim APrn As Double
    Dim AContract As Double
    Dim ASupplies As Double
    Dim ASuppliesType As String
    Dim APO As Double
    Dim ACC As Double
    Dim AGenOff As Double
    Dim ACOSA As Double
    Dim AOfficeDepot As Double
    Dim AEquip As Double
    Dim ALand As Double
    Dim ATort As Double
    Dim AInterest As Double
    Dim ARemark As String
    Dim TotalBranchAllocation As Double
    
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset

Private Sub Form_Unload(cancel As Integer)
    If Not rs Is Nothing Then
       If rs.State = adStateOpen Then rs.Close
       Set rs = Nothing
    End If
    If Not Conn Is Nothing Then
       If Conn.State = adStateOpen Then Conn.Close
       Set Conn = Nothing
    End If
    Unload Me
End Sub

   
Private Sub cboABranch_LostFocus()
     'If ABranch = "" Then
        'MsgBox ("You must pick a branch")
        'cboABranch.SetFocus
     'End If
End Sub

Private Sub cmdADel_Click()
    Dim check
    Dim cancel
    Beep
    check = MsgBox(" Are you sure you want to delete Current Record? ", vbQuestion + vbYesNo, "Confirm")

    If check = vbYes Then
        rs.Delete
        rs.MoveNext
    Else
        cancel = True
    End If
End Sub

Private Sub cmdANew_Click()

    rs.AddNew
    
    cboABranch.Text = ""
    cboASuppliesType.Text = ""
    txtASal.Text = 0
    txtAAwd.Text = 0
    txtABen.Text = 0
    txtAOT.Text = 0
    txtATrav.Text = 0
    txtATrans.Text = 0
    txtATraining.Text = 0
    txtARCU.Text = 0
    txtAPrn.Text = 0
    txtAContract.Text = 0
    lblASupResult.Caption = "0.00"
    txtACC.Text = 0
    txtAPO.Text = 0
    txtAGenOff.Text = 0
    txtACOSA.Text = 0
    txtAOfficeDepot.Text = 0
    txtAEquip.Text = 0
    txtALand.Text = 0
    txtATort.Text = 0
    txtAInterest.Text = 0
    txtARemark.Text = " "
    txtTotalAlloc = 0
    
End Sub

Private Sub cmdAReset_Click()
    Dim check
    Dim cancel
    Beep
    check = MsgBox(" Are you sure you want to ERASE every field? ", vbQuestion + vbYesNo, "Confirm")

    If check = vbYes Then
        rs.Update
    Else
        cancel = True
    End If
End Sub

Private Sub cmdNav_Click(Index As Integer)
    
    Select Case Index
        Case 0      'First Record
            rs.MoveFirst
        Case 1      'Previous Record
            rs.MovePrevious
            If rs.BOF Then rs.MoveFirst
        Case 2      'Next Record
            rs.MoveNext
            If rs.EOF Then rs.MoveLast
        Case 3      'Last Record
            rs.MoveLast
    End Select
        
End Sub

Private Sub Form_Load()

    'Branch Dropdown
    cboABranch.AddItem ""
    cboABranch.AddItem "EXEC"
    cboABranch.AddItem "AMB"
    cboABranch.AddItem "CLAIMS"
    cboABranch.AddItem "ISB"
    cboABranch.AddItem "POB"
            
    'Supplies Type dropdown
    cboASuppliesType.AddItem ""
    cboASuppliesType.AddItem "COSA"
    cboASuppliesType.AddItem "Office Deport"
    cboASuppliesType.AddItem "Credit Card"
    cboASuppliesType.AddItem "Contracts"
            
    'Set and make the connection to the database.
    Set Conn = New ADODB.Connection
        
    'define the recordset access statement
    Dim strSQL As String
    strSQL = "SELECT * FROM Allocation"
    Set rs = New ADODB.Recordset
        
    On Error GoTo Err_Exit
    
    Conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbFSF;Data Source=Server1"
    Conn.Open
    
    With rs
        .ActiveConnection = Conn
        .CursorLocation = adUseServer
        .CursorType = adOpenDynamic
        .LockType = adLockOptimistic
        .Source = strSQL
        .Open
    End With

Exit Sub

Err_Exit:
    ADOerror
End Sub

Private Sub cmdAClose_Click()
    Unload Me
    Load Splash
    Splash.Show vbModeless
End Sub

Private Sub cmdASave_Click()
    ABranch = cboABranch.Text
    ASuppliesType = cboASuppliesType.Text
    ASal = CDbl(txtASal.Text)
    AAwd = CDbl(txtAAwd.Text)
    ABen = CDbl(txtABen.Text)
    AOT = CDbl(txtAOT.Text)
    ATrav = CDbl(txtATrav.Text)
    ATrans = CDbl(txtATrans.Text)
    ATraining = CDbl(txtATraining.Text)
    ARCU = CDbl(txtARCU.Text)
    APrn = CDbl(txtAPrn.Text)
    AContract = CDbl(txtAContract.Text)
    APO = CDbl(txtAPO.Text)
    ACC = CDbl(txtACC.Text)
    ACOSA = CDbl(txtACOSA.Text)
    AOfficeDepot = CDbl(txtAOfficeDepot.Text)
    'AGenOff = CDbl(txtAGenOff.Text)
    AGenOff = CDbl(ACOSA + AOfficeDepot)
    txtAGenOff = FormatCurrency(AGenOff)
    ASupplies = CDbl(APO + ACC + AGenOff)
    lblASupResult.Caption = FormatCurrency(ASupplies)
    AEquip = CDbl(txtAEquip.Text)
    ALand = CDbl(txtALand.Text)
    ATort = CDbl(txtATort.Text)
    AInterest = CDbl(txtAInterest.Text)
    ARemark = txtARemark.Text
    
    'ASal and ABen not included
    TotalBranchAllocation = CDbl(AAwd + AOT + ATrav + ATrans + ATraining + _
                                ARCU + APrn + AContract + ASupplies + _
                                AEquip + ALand + ATort + AInterest)
    txtTotalAlloc = FormatCurrency(TotalBranchAllocation)
    
    'Assigning values
    With rs
        .Fields("ABranch") = cboABranch.Text 
        .Fields("ASuppliesType") = cboASuppliesType.Text
        .Fields("ASal") = CDbl(txtASal.Text)
        .Fields("AAwd") = CDbl(txtAAwd.Text)
        .Fields("ABen") = CDbl(txtABen.Text)
        .Fields("AOT") = CDbl(txtAOT.Text)
        .Fields("ATrav") = CDbl(txtATrav.Text)
        .Fields("ATrans") = CDbl(txtATrans.Text)
        .Fields("ATraining") = CDbl(txtATraining.Text)
        .Fields("ARCU") = CDbl(txtARCU.Text)
        .Fields("APrn") = CDbl(txtAPrn.Text)
        .Fields("AContract") = CDbl(txtAContract.Text)
        .Fields("APO") = CDbl(txtAPO.Text)
        .Fields("ACC") = CDbl(txtACC.Text)
        .Fields("ACOSA") = CDbl(txtACOSA.Text)
        .Fields("AOfficeDepot") = CDbl(txtAOfficeDepot.Text)
        .Fields("AGenOff") = CDbl(txtAGenOff)
        .Fields("ATrans") = CDbl(txtATrans.Text)
        .Fields("ASupplies") = CDbl(ASupplies)
        .Fields("AEquip") = CDbl(txtAEquip.Text)
        .Fields("ALand") = CDbl(txtALand.Text)
        .Fields("ATort") = CDbl(txtATort.Text)
        .Fields("AInterest") = CDbl(txtAInterest.Text)
        .Fields("ARemark") = txtARemark.Text
        .Fields("BranchAllotment") = CDbl(txtTotalAlloc)
        .Update
      End With
        
End Sub

Private Sub ADOerror()
'/ Enumerate the Errors collection and display properties of each Error object
   Dim errCollection As Variant
   Dim errLoop  As Error
   Dim strError As String
   Dim iCounter As Integer

   On Error Resume Next    '/ in case ADO connection not set or other init problems
   iCounter = 1
   strError = " "
   For Each errLoop In errCollection
      With errLoop
         strError = _
            "Error #" & iCounter & vbCrLf & _
            "  ADO Error #" & .Number & vbCrLf & _
            "  Description - " & .Description & vbCrLf & _
            "  Error Source - " & .Source & vbCrLf
            Debug.Print strError
            iCounter = iCounter + 1
      End With
   Next
End Sub


Thanks in advance.


Reply With Quote
  #2  
Old May 17th, 2006, 02:05 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 57 m 26 sec
Reputation Power: 181
I have a question. If you can't see records how do you know you can write data into the db?

You should step through your code with the debugger to isolate what is failing.

Since you're using integrated sql security, make sure the user account of the user running your program has sufficient permission in the sql db.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old May 17th, 2006, 02:48 PM
Ausburgh Ausburgh is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 5 Ausburgh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 32 sec
Reputation Power: 0
Quote:
Originally Posted by Doug G
I have a question. If you can't see records how do you know you can write data into the db?



Thanks for responding.

I see the updates on the SQL server side whenever I open my "Allocation" table.

Reply With Quote
  #4  
Old May 17th, 2006, 04:59 PM
Ausburgh Ausburgh is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 5 Ausburgh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 32 sec
Reputation Power: 0
Now I can see the first record only and I can edit that record only.

Anybody know how I can move to the subsequent records?

I added the following code to my Form_Load():

Code:
With rs
        cboABranch.Text = !ABranch
        cboASuppliesType.Text = !ASuppliesType & ""
        txtASal.Text = !ASal
        txtAAwd.Text = !AAwd & ""
        txtABen.Text = !ABen & ""
        txtAOT.Text = !AOT & ""
        txtATrav.Text = !ATrav & ""
        txtATrans.Text = !ATrans & ""
        txtATraining.Text = !ATraining & ""
        txtARCU.Text = !ARCU & ""
        txtAContract.Text = !AContract & ""
        txtAPrn.Text = !APrn & ""
        lblASupResult.Caption = !ASupplies & ""
        txtAPO.Text = !APO & ""
        txtACC.Text = !ACC & ""
        txtAGenOff.Text = !AGenOff & ""
        txtACOSA.Text = !ACOSA & ""
        txtAOfficeDepot.Text = !AOfficeDepot & ""
        txtAEquip.Text = !AEquip & ""
        txtALand.Text = !ALand & ""
        txtATort.Text = !ATort & ""
        txtAInterest.Text = !AInterest & ""
        txtARemark.Text = !ARemark & ""
        txtTotalAlloc.Text = !BranchAllotment & ""        
    End With

Reply With Quote
  #5  
Old May 18th, 2006, 08:45 AM
Ausburgh Ausburgh is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 5 Ausburgh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 32 sec
Reputation Power: 0
I got the solution.

Thanks

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > VB 6.0 Connection to SQL Server Issues


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT