|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > VB6 Problem, Looking For An Answer Please |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|