| | |
VB6 - Query/StoredProc works in Access but not in VB6 - please help!
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 143
Reputation:
Solved Threads: 16
Hi,
I've got a bit of a problem with an application I am writing at the moment. I know it has to be something small which I'm missing, but I can't figure out what it is.
Basically, I have a Query (or Stored Procedure if you prefer) in an Access2000 database called qryApptList which has one parameter (DateOfAppt). This parameter is Text (as is the Date field in the database table).
If I run the query in Access, it prompts for the Date. I enter it in and it returns my results as it should. If I then do the same thing in VB6 using ADODB, it brings back nothing.
My VB6 code...
All this code runs within a separate class module which is called from a form.
And if it helps... my SQL query.
I have had it working once and I had a recordcount of 1 in the recordset (I only have one record in the table by the way). I haven't knowingly changed anything but now I get 0 records every time.
Any help would be massively appreciated as I'm tearing out what little hair I have left!
I've got a bit of a problem with an application I am writing at the moment. I know it has to be something small which I'm missing, but I can't figure out what it is.
Basically, I have a Query (or Stored Procedure if you prefer) in an Access2000 database called qryApptList which has one parameter (DateOfAppt). This parameter is Text (as is the Date field in the database table).
If I run the query in Access, it prompts for the Date. I enter it in and it returns my results as it should. If I then do the same thing in VB6 using ADODB, it brings back nothing.
My VB6 code...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private m_oConnection As ADODB.Connection Private m_oCmdGetAppointments As ADODB.Command 'Open the database connection Public Sub OpenDatabaseConnection() On Error GoTo ErrorHandler If Len(m_sDatabasePath) = 0 Then m_sDatabasePath = m_oParentForm.FileSelection End If Set m_oConnection = New ADODB.Connection m_oConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & m_sDatabasePath If m_oConnection.State <> adStateOpen Then Set m_oConnection = Nothing MsgBox "Could not open connection to database", vbCritical + vbOKOnly, App.Title Exit Sub End If Exit Sub ErrorHandler: HandleError "clsDatabaseHandler:OpenDatabaseConnection Sub" End Sub 'Method to get the appointments from the database Public Function GetAppointments(ByVal sDate As String, ByRef oRsAppts As ADODB.Recordset) On Error GoTo ErrorHandler If m_oCmdGetAppointments Is Nothing Then Set m_oCmdGetAppointments = New ADODB.Command With m_oCmdGetAppointments Set .ActiveConnection = m_oConnection .CommandText = "qryApptList" .CommandType = adCmdStoredProc .Parameters.Append .CreateParameter("DateOfAppt", adVarChar, adParamInput, 11) End With End If m_oCmdGetAppointments.Parameters("DateOfAppt") = sDate Set oRsAppts = New ADODB.Recordset oRsAppts.Open m_oCmdGetAppointments, , adOpenStatic, adLockReadOnly Exit Function ErrorHandler: HandleError "clsDatabaseHandler:GetAppointments Function" End Function
All this code runs within a separate class module which is called from a form.
And if it helps... my SQL query.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
PARAMETERS DateOfAppt Text ( 255 ); SELECT tblAppointments.ApptId, tblAppointments.User, tblAppointments.ApptDate, tblAppointments.ApptTime, tblAppointments.ClientId, tblAppointments.Comments, tblClients.Title, tblClients.FirstName, tblClients.Surname, tblClients.ContactNumber1 FROM tblClients INNER JOIN tblAppointments ON tblClients.ClientId=tblAppointments.ClientId WHERE tblAppointments.ApptDate=[DateOfAppt];
I have had it working once and I had a recordcount of 1 in the recordset (I only have one record in the table by the way). I haven't knowingly changed anything but now I get 0 records every time.
Any help would be massively appreciated as I'm tearing out what little hair I have left!
•
•
Join Date: Nov 2007
Posts: 143
Reputation:
Solved Threads: 16
0
#3 Nov 21st, 2009
After much hair pulling and head scratching, I've got it working and believe it or not, it was a complete schoolboy error as I didn't clean up afterwards and destroy the command object so it was holding the original parameter value.
So I've moved the command from being module based to just method based (don't know why I had it in the module to start with!) and the amended code is as follows:
Thanks to anyone who looked in.
So I've moved the command from being module based to just method based (don't know why I had it in the module to start with!) and the amended code is as follows:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Public Function GetAppointments(ByVal sDate As String, ByRef oRsAppts As ADODB.Recordset) On Error GoTo ErrorHandler Dim oCommand As ADODB.Command If oCommand Is Nothing Then Set oCommand = New ADODB.Command With oCommand Set .ActiveConnection = m_oConnection .CommandText = "qryApptList" .CommandType = adCmdStoredProc .Parameters.Append .CreateParameter("DateOfAppt", adVarChar, adParamInput, 20) End With End If oCommand.Parameters("DateOfAppt") = sDate Set oRsAppts = New ADODB.Recordset oRsAppts.CursorLocation = adUseClient oRsAppts.Open oCommand, , adOpenStatic, adLockReadOnly Set oCommand = Nothing Exit Function ErrorHandler: HandleError "clsDatabaseHandler:GetAppointments Function" End Function
Thanks to anyone who looked in.
•
•
Join Date: Nov 2009
Posts: 4
Reputation:
Solved Threads: 0
Hi :
I have this problem, and I'm trying to solve it, I need your help#####@@@
write aprogramto generate a business travel express attaachment for an income tax return. The program should request ias input the name of the organization visited, the date and location of the visit,and the expenses for meals and entertainment,airplane fare,loding,and taxi fares.(Only 50% of the expenses for meals and entertainment are deductible) . Sub procedures should be used for the input and output .
I have this problem, and I'm trying to solve it, I need your help#####@@@
write aprogramto generate a business travel express attaachment for an income tax return. The program should request ias input the name of the organization visited, the date and location of the visit,and the expenses for meals and entertainment,airplane fare,loding,and taxi fares.(Only 50% of the expenses for meals and entertainment are deductible) . Sub procedures should be used for the input and output .
•
•
Join Date: Nov 2007
Posts: 143
Reputation:
Solved Threads: 16
0
#5 Nov 22nd, 2009
•
•
•
•
Hi :
I have this problem, and I'm trying to solve it, I need your help#####@@@
write aprogramto generate a business travel express attaachment for an income tax return. The program should request ias input the name of the organization visited, the date and location of the visit,and the expenses for meals and entertainment,airplane fare,loding,and taxi fares.(Only 50% of the expenses for meals and entertainment are deductible) . Sub procedures should be used for the input and output .
However, I'd recommend doing some research and finding the points that you think you'll have problems with. If you have code that you have written already that is causing you problems then even better, you could post it up and people can then see if they can spot the error or improve it in any way.
As it stands, it appears (from your post) that you are hoping for someone to provide you with the code to work with.
![]() |
Similar Threads
- create a query in access from vb6 (Visual Basic 4 / 5 / 6)
- Query from VB6 (Visual Basic 4 / 5 / 6)
- How can i access data from MS Access using VB6 (I need the connection code) (Visual Basic 4 / 5 / 6)
- VB6 and MS Access Problem (Visual Basic 4 / 5 / 6)
- Update user-level security (MS Access) in VB6 (Visual Basic 4 / 5 / 6)
- VB6 & Access (user name, network printer, reminders) (Visual Basic 4 / 5 / 6)
- VB6 Access error Please Please Help !!! (Visual Basic 4 / 5 / 6)
- How to set user rights in ms.access from vb6 (Visual Basic 4 / 5 / 6)
- New key word not recoginized in VB6 connecting to Access (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Final year projects in VB
- Next Thread: Help me in this problem(@)))
Views: 740 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 access activex add ado append application array banned basic bmp box calculator click client code coffeehouse college column convert copy creative database designer desktop dissertations dissertationthesis edit error excel filter flex form game header ide image implements inboxinvb installation installer interaction keypress listview machine macro mail match memory noob number open outlook password pause pdf picture pos prime print program programmer prompt query random range range-objects readfile record registration remotesqlserverdatabase report reports retrieve save score search sites spectateswamp sql string struct subroutine table textbox time timer variable variables vb vb6 vb6.0 vba vista visual visualbasic web window windows





