Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual 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 Dev Shed Forums Sponsor:
  #1  
Old January 18th, 2004, 10:22 AM
Octopulse Octopulse is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 Octopulse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question VB6 Problem, Looking For An Answer Please

Hello,

I dont like asking for help unless im in a real bind, but ive been trying to find an answer to my VB6 problem for 3 days now, its time to bump this up to an expert, I hope someone here can point out where this newbie is going wrong, please


I want to create a simple form which has the following elements.....

1. An Adodc control called dataControlClient, it uses a DSN connection to database CCDB, its recordsource is set to table Client

2. A DataGrid called dataGridAxisCodes thats bound to the Adodc, the grid displays the result of an SQL on Client

3. 3 text boxes... txtlastName, txtfirstName, and txtID also bound to the Adodc

4. 2 Buttons to call the SEARCH and CLEAR Sub-routines

Once the basic functionality is debugged i am gonna use the form as a "backbone" for a more sophisticated program. In my program I want to use the text-boxes for BOTH displaying results and entering search terms, i dont wanna leave the form to do a search, I wanna do that by clearing all the text-boxes and then entering ONE search term into any one box to search by.


OK now heres my problem....

the program runs as expected while single-stepping through the debugger, but, it doesnt when in run-time, i thought as long as I entered the data exactly the same the program should react the same wiether stepping through the debugger or in run-time.

I have a "search" subroutine, when in the debugger if no records are returned by a search, the program sits at the botton of the search subroutine waiting for input, if i give another search term and send control back through the search subroutine again everything works fine, it gives another "no record found" message and then stops at the end of the search routine again
waiting for more input.


Ok, it works as it should in the debugger, but when the program is in run-time something different is happening


When in run-time the first search that returns "no records found" runs fine, but, after that whenever a search term is entered and the Search subroutine is called again, regardless of wiether or not the search-term will produce a find or not, my text-box data is getting reset to Null when re-entering the search subroutine, which of course gives BOTH the "all fields empty" and "no
records found" messages.


There are four conditions being checked while searching, the last condition is causing the problem at hand...

1. All fields empty when searching - OK

2. More than one field has a value when search perfoRmed - OK

3. Record Found - OK

4. Record Not Found - ERROR ON SECOND RUN


Here is the code for the form, dont be too harsh please, im still learning....

Code:
Option Explicit
Dim cnnCCDB As New ADODB.Connection
Dim rstAxisCodes As New ADODB.Recordset
Dim sSQLAxisCodesGet As String
Dim sSQLClear As String



Private Sub cmdClear_Click()

txtLastName = ""
txtFirstName = ""
txtID = ""

If rstAxisCodes.Fields.Count <> 0 Then
     rstAxisCodes.Close
End If

rstAxisCodes.Open sSQLClear, cnnCCDB, adOpenForwardOnly, adLockReadOnly

cmdClear.Enabled = False
cmdSearch.Enabled = True

End Sub



Private Sub cmdSearch_Click()

cmdSearch.Enabled = False
cmdClear.Enabled = True

If txtLastName <> "" And txtFirstName = "" And txtID = "" Then
	dataControlClient.RecordSource = "SELECT * FROM Client WHERE [Last Name] Like '" _
		     & Trim(txtLastName) & "%'"
	dataControlClient.Refresh

ElseIf txtLastName = "" And txtFirstName <> "" And txtID = "" Then
	dataControlClient.RecordSource = "SELECT * FROM Client WHERE [First Name] Like '" _
		& Trim(txtFirstName) & "%'"
	dataControlClient.Refresh

ElseIf txtLastName = "" And txtFirstName = "" And txtID <> "" Then
	dataControlClient.RecordSource = "SELECT * FROM Client WHERE [Client ID Number] Like '" _
		& Trim(txtID) & "%'"
	dataControlClient.Refresh

ElseIf txtLastName = "" And txtFirstName = "" And txtID = "" Then
	MsgBox "All Fields Are Empty"
	Call cmdClear_Click

Else: MsgBox "Only One Field May Have A Value"
                Call cmdClear_Click

End If

If dataControlClient.Recordset.RecordCount = 0 Then
	MsgBox "No Records Found"
	cmdClear.Enabled = False
	cmdSearch.Enabled = True
Else
	Call AxisCodesGet
End If

End Sub



Private Sub Form_Load()

cnnCCDB.Open "DSN=CCDB"
dataControlClient.CommandType = adCmdText
sSQLClear = "SELECT Client.[Client ID Number] FROM Client  WHERE Client.[Client ID Number] = 9999;"

cmdFirst.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
cmdLast.Enabled = False

Call cmdClear_Click

End Sub



Private Sub AxisCodesGet()

sSQLAxisCodesGet = "SELECT [Client Axis Codes].[Axis Code], [Axis Code Descriptions].Description " _
	& "FROM [Client Axis Codes] INNER JOIN [Axis Code Descriptions] ON [Client Axis Codes].[Axis Code] = [Axis Code Descriptions].[Axis Code] " _
	& "WHERE [Client Axis Codes].[Client ID Number] = " & Val(txtID) & ";"

rstAxisCodes.Close
rstAxisCodes.CursorLocation = adUseClient
rstAxisCodes.Open sSQLAxisCodesGet, cnnCCDB, adOpenForwardOnly, adLockReadOnly
Set dataGridAxisCodes.DataSource = rstAxisCodes

End Sub



THANKS FOR ANY ATTEMPTS TO ASSIST, I HOPE SOMEONE CAN POINT OUT WHAT IS HAPPENIN' HERE

AND HAVE A GOOD DAY

Last edited by Octopulse : January 18th, 2004 at 02:49 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > VB6 Problem, Looking For An Answer Please


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


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





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