No Value given for one or more required parameters in Vb6 - vb6

I'm new to Vb6.
I haven't inserted data in my database and when I run the program, an error shows No Value given for one or more required parameters
Here's the code:
Dim list As ListItem, r As Integer
If recset.State = adStateOpen Then recset.Close
recset.Open "SELECT StudentId, LastName, FirstName, MiddleName FROM Students ORDER BY StudentId", rainCon, adOpenStatic, adLockOptimistic
If recset.RecordCount > 1 Then
MsgBox "No Data Found!", vbInformation, ""
Else
ListView1.ListItems.Clear
Do While Not recset.EOF
r = r + 1
Set list = ListView1.ListItems.Add(, , r)
list.SubItems(1) = recset(0).Value
list.SubItems(2) = recset(1).Value
list.SubItems(3) = recset(2).Value
list.SubItems(4) = recset(3).Value
recset.MoveNext
Loop
End If
Then highlights recset.Open part. How to control or fix this error?

When I tried to re-check my code and database multiple times. I found out that there was a missing attribute in my students table. The code was fully functional.

Find out the full working code.
Private Sub cmdAddItemtoListBox_Click()
'Enter Code here....
End Sub
Change database path, name, and table as per your data.
Output Screenshot
Dim xCon As New ADODB.Connection
Dim rsTable As New ADODB.Recordset
Dim StrSqlQuery As String
Dim Counter As Integer
Dim list As ListItem
If xCon.State = 1 Then xCon.Close
xCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Test\Test.mdb;Persist Security Info=False"
'
StrSqlQuery = ""
StrSqlQuery = "Select * from Data Order by PrintSl"
If rsTable.State = 1 Then rsTable.Close
rsTable.CursorLocation = adUseClient
rsTable.Open StrSqlQuery, xCon, adOpenStatic, adLockReadOnly
If rsTable.RecordCount > 0 Then
rsTable.MoveFirst
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Add , , "ID"
ListView1.ColumnHeaders.Add , , "Customer Name"
ListView1.ColumnHeaders.Add , , "Address"
ListView1.ColumnHeaders.Add , , "Pincode"
ListView1.ColumnHeaders.Add , , "Amount"
Do While Not rsTable.EOF
Counter = ListView1.ListItems.Count + 1
Set list = ListView1.ListItems.Add(, , Counter)
list.ListSubItems.Add , , rsTable!CUSTOMERNAME
list.ListSubItems.Add , , rsTable!ADDRESS1
list.ListSubItems.Add , , rsTable!pin
list.ListSubItems.Add , , rsTable!LOAN_AMOUNT
rsTable.MoveNext
Loop
Else
MsgBox "No record found in the table.", vbCritical
End If
If rsTable.State = 1 Then rsTable.Close
If xCon.State = 1 Then xCon.Close
MsgBox "Record Add Successfully", vbInformation

Related

Out of Memory error when trying to connect to oracle database (VB6)

when I m trying to set Recordset using oracle connection string, I m getting OUt of memory error.
on line "rsLIS.Open sql, gConnLIS, adOpenStatic, adLockReadOnly"
However some time it works like once in 5-6 attempts
but when it works it gives error on some other line
on line "If rsLink.Fields(2).value = rsLIS.Fields(1).value Then"
here are the things which I tried :
instead of directly using recordset, I tried to create array (GetRows) method.
Even though recordset count is 26 but UBound of array is showing 1
I have trying changing 3rd argument value from static to forward only
in line ""rsLIS.Open sql, gConnLIS, adOpenStatic, adLockReadOnly""
it also didn't work, it was showing recordset.count as 0
Did try after restarting the client system still same
I m getting this error on client side and since at my place I don't have development environment to debug
Error is "OUT OF MEMORY"
Public Function GetResults_New(MachName As String, patid As String, bCheckDate As Boolean, SendAssay As Boolean) As ADODB.Recordset
On Error GoTo errdesc
Call ShowTempMsg("Line 1")
Dim bXVar As Boolean
Dim i, j As Integer
Dim tmplis, tmporder
Dim tmpresult
bXVar = False
Dim rec_result As New ADODB.Recordset
Dim rsLink As New ADODB.Recordset
Dim rsLIS As New ADODB.Recordset
Dim xSampleIdType As String
gAppPath = AddEditINIfile("VAHSIF.INI", "IF", "sLinkPath", "")
xSampleIdType = AddEditINIfile(gAppPath & "\sLinkConfig.ini", MachName, "SampleIdType", "SampleId1", False)
Call Open_Connection
Call Open_Connection_LIS
rec_result.CursorLocation = adUseClient
If SendAssay = True Then
rec_result.Fields.Append "machineparamid", adBSTR, 50
rec_result.Fields.Append "Assayno", adBSTR, 50
rec_result.Fields.Append "SType", adBSTR, 50
rec_result.Fields.Append "Dilution", adBSTR, 50
Else
rec_result.Fields.Append "machineparamid", adBSTR, 50
rec_result.Fields.Append "SType", adBSTR, 50
rec_result.Fields.Append "Dilution", adBSTR, 50
End If
rec_result.Open
\
'Link Query For Mapped Params.
sql = "SELECT EquipParamMapping.EquipId, EquipParamMapping.EquipParamCode, EquipParamMapping.LISParamCode, EquipParamMapping.EquipAssayNo from EquipParam, EquipParamMapping where equipParam.equipid = equipparammapping.equipid and equipparam.equipparamcode = equipparammapping.equipparamcode and EquipParam.EquipID = '" & MachName & "' and EquipParam.isProgram = 'Y'"
**rsLink.Open sql, gConn, adOpenStatic, adLockReadOnly**
If enumConnTo = connOracle Then
sql = "select " & xSampleIdType & " , LIS_Param_Code From SL_21CI_View_sampleid_Orders where " & xSampleIdType & " || SuffixCode = '" & patid & "' and isApplicable <> 'N' "
Else
sql = "select " & xSampleIdType & " , LIS_Param_Code From SL_21CI_View_sampleid_Orders where " & xSampleIdType & " + cast(SuffixCode as varchar(20)) = '" & patid & "' and isApplicable <> 'N' "
End If
rsLIS.Open sql, gConnLIS, adOpenStatic, adLockReadOnly
While Not rsLIS.EOF
If bXVar = True Then
rsLink.MoveFirst
bXVar = False
End If
While Not rsLink.EOF
bXVar = True
**If rsLink.Fields(2).value = rsLIS.Fields(1).value Then**
If SendAssay = True Then
rec_result.AddNew
rec_result("machineparamid") = rsLink.Fields("EquipParamCode")
rec_result("Assayno") = rsLink.Fields("EquipAssayNo")
rec_result("SType") = " "
rec_result("Dilution") = "0"
rec_result.Update
rec_result.MoveFirst
Else
rec_result.AddNew
rec_result("machineparamid") = rsLink.Fields("EquipParamCode")
rec_result("SType") = " "
rec_result("Dilution") = "0"
rec_result.Update
rec_result.MoveFirst
End If
GoTo NextParam
End If
rsLink.MoveNext
Wend
NextParam:
rsLIS.MoveNext
Wend
Set GetResults_New = rec_result
Exit Function
errdesc:
Call InsertIntoLogWithFileName("Transaction.GetResults_New" & vbNewLine & sql & vbNewLine & err.Description & "ErrLine : " & ErrLine)
End Function
Thanks
That still leaves the question on which line the error occurs. Also: "it also didn't work, it was showing recordset.count as 0". The RecordSet.Count property depends on the provider. Use a function similar to this instead:
Public Function RecordCount(ByVal cn As ADODB.Connection, ByVal sTable As String) As Long
Dim sSQL As String, lRetVal as Long
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
sSQL = "SELECT COUNT(1) AS RecCount FROM " & sTable & ";"
Call rs.Open(sSQL, cn)
If Not (rs.BOF And rs.EOF) Then
lRetVal = rs.Fields("RecCount").Value
Else
lRetVal = -1
End If
Call rs.Close
Set rs = Nothing
RecordCount = lRetVal
End Function
The .Count property might also very well be the cause of the Out of memory error, as I seem to remember that for determing the number of records, it loads all records (from the server) to count them. But I might be wrong there.

How to fix this Operation is not allowed when object is closed

List item
How to fix this error" Operation is not allowed when the object is closed"?
This for the adding and display stored data in listview in vb6
Dim connect As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim a As Integer
Dim b As Integer
Dim x As Long
Dim c As String
Option Explicit
Private Sub Command1_Click()
rs.AddNew 'this line shows the error
ado.Recordset.Fields("EMPID").Value = emp.Text
ado.Recordset.Fields("DEPARTMENT") = Text2.Text
ado.Recordset.Fields("EMPNAME") = Text1.Text
ado.Recordset.Fields("TIMEIN") = DTPicker3.Value
ado.Recordset.Fields("TIMEOUT") = DTPicker4.Value
ado.Recordset.Fields("LOGDATE") = DTPicker2.Value
rs.Update
End Sub
Private Sub Command2_Click()
a = DateDiff("d", DTPicker1, DTPicker2)
b = DateDiff("h", DTPicker3, DTPicker4)
x = a * b
c = x * 52.5
Text7.Text = "Hours:" & x & " Days:" & a & "$ " & c
End Sub
Private Sub Form_Load()
connect.Open _
"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\MIS02\Desktop\FILE.accdb;Persist Security Info=False"
With ListView1.ColumnHeaders
.Add , , "EMPID", Width / 15, lvwColumnLeft
.Add , , "DEPARTMENT", Width / 10, lvwColumnCenter
.Add , , "EMPNAME", Width / 12, lvwColumnCenter
.Add , , "TIMEIN", Width / 12, lvwColumnCenter
.Add , , "TIMEOUT", Width / 12, lvwColumnCenter
.Add , , "LOGDATE", Width / 10, lvwColumnCenter
End With
End Sub
Sub dbconnection()
connect.Open _
"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\MIS02\Desktop\FILE.accdb;Persist Security Info=False"
End Sub
Sub loaddata()
Dim list As ListItem
ListView1.ListItems.Clear
dbconnection
rs.Open "Select *from Attendance", con, adOpenDynamic,
adLockOptimistic
Do Until rs.EOF
Set list = ListView1.ListItems.Add(, , rs!Employee)
list.SubItems(1) = rs!Department
list.SubItems(2) = rs!Surename
list.SubItems(3) = rs!FirstName
list.SubItems(4) = rs!TimeIn
list.Subitems(5)=rs!Timeout
list.SubItems(6) = rs!DateRecord
rs.MoveNext
Loop
=======================================================
I expect that i can store and display data in listview.
You declare connect as a connection and seems like you tend to use it (since you're calling dbconnection method). But at the same time you pass con as a parameter for opening your recordset. Probably this variable either not exists or if exists on a global level - not initialized/opened correctly.

Creating a Pivot table with VBScript

I am trying to create a pivot table using VBScript. I think I am close to achieving it, but I do not know how to create the report filter and set up the filter for "Internal", or how to use sum instead of count in the values.
That is what I have now:
xlA1 = 1
xlDatabase = 1
xlRowField = 1
xlColumnField = 2
xlFilterField = 3
Set xlBook1 = objExcel.WorkBooks.Open(ws_path & "FINAL.xlsx")
set rngData =xlBook1.Sheets("NONPO").Usedrange
set rngReport = xlBook1.Sheets("NONPO").Range("CE1")
set pvtCache = xlBook1.pivotCaches.add(xlDatabase, rngData.address(true, true, xlA1, true))
set pvtTable = pvtCache.createPivotTable(rngReport, "Pivot1")
pvtTable.pivotFields("Date").orientation =xlRowField
pvtTable.pivotFields("Country Code").orientation = xlColumnField
pvtTable.pivotFields("Agent Type").orientation = xlFilterField
'*****Here I should Use filter as "Internal"*****
pvtTable.pivotFields("Hours").orientation = xlsum *****xlsum is not working*****
should work like this...
With pvtTable.pivotFields("Hours")
.orientation = 4
.Function = xlSum
End With
I believe this is what you want.
pt.AddDataField(pt.PivotFields("Hours"), "Hours", _
Excel.XlConsolidationFunction.xlSum)
So, the whole thing should look kind of like this (modify for your specific needs).
Private Sub CreatePivotTable(tableName As String)
Dim targetSheet As Excel.Worksheet = ExcelApp.Sheets.Add
Dim ptName As String = "MyPivotTable"
'We'll assume the passed table name exists in the ActiveWorkbook
targetSheet.PivotTableWizard(Excel.XlPivotTableSourceType.xlDatabase, _
tableName, targetSheet.Range("A5"))
targetSheet.Select()
Dim pt As Excel.PivotTable = targetSheet.PivotTables(1)
'To be professional or merely resuable, the name could be passed as parameter
With pt.PivotFields("Order Date")
.Orientation = Excel.XlPivotFieldOrientation.xlRowField
.Position = 1
End With
pt.AddDataField(pt.PivotFields("Order Total"), "Order Count", _
Excel.XlConsolidationFunction.xlCount)
pt.AddDataField(pt.PivotFields("Order Total"), "Total for Date", _
Excel.XlConsolidationFunction.xlSum)
'--OR--
'AddPivotFields(pt, "Order Total", "Order Count", _
' Excel.XlConsolidationFunction.xlCount)
'AddPivotFields(pt, "Order Total", "Total For Date", _
' Excel.XlConsolidationFunction.xlSum)
Marshal.ReleaseComObject(pt)
Marshal.ReleaseComObject(targetSheet)
End Sub

recordset.close got wrong help plssss

Help my code got wrong it says:
Either BOF or EOF is True, or the current record has been deleted,Requested operation requires a current record.
i think this rs.close has a problem or where can i set the rs.close? because i set and used recordset twice.
anyone can help? please fix my code.
Public Function borrowersName(ByVal Iname, ByVal Imod, ByVal Icat, ByRef BFname, ByRef BLname) As Boolean
Dim dateReturned As String
'select firt the primary key of the item
qry1 = "select tblitem_id from tblitem inner join tblcategory on tblitem.tblcategory_id=tblcategory.tblcategory_id where tblitem.item_name='" + Iname + "' and tblitem.item_model='" + Imod + "' and tblcategory.category_name='" + Icat + "'"
rs.Open qry1, conn
qry1Result = rs.Fields(0).Value
rs.Close
qry2 = "SELECT date_returned,Firstname,Lastname FROM tblborrowers where tblitem_id='" & qry1Result & "' ORDER BY tblborrowers_id DESC LIMIT 1"
rs.Open qry2, conn
dateReturned = rs.Fields(0).Value
If dateReturned <> "" Then
borrowersName = True
BFname = rs.Fields(1).Value
BLname = rs.Fields(2).Value
Else
borrowersName = False
End If
Set rs = Nothing
End Function
You do have the recordset Open and Close methods in the right order, so there is no problem there.
The error "Either BOF or EOF is True, or the current record has been deleted" simply means that one of your SELECT queries has returned zero records. What you do about that depends on your requirements. For example, you could test for Not rs.EOF before attempting to read a field value.

compiler error when i run my program

Private Sub Form_Activate()
Dim st1 As String
'if txtmode 1 fetch record of id from database
If txtmode.Text = "1" Then
'SQL statement
openCon
st1 = "SELECT Customer_name, Address1, Address2, City, Contact FROM customer WHERE id=" & txtid.Text
recSet.Open st1, conn, adOpenDynamic, adLockOptimistic
recSet.MoveFirst
If recSet.Fields("Customer_name").Value <> vbNullString Then
txtCustomer_name = recSet.Fields("Customer_name").Value
Else
txtCustomer_name = ""
End If
When I run my program, I get an error:
compiler error : invalid use of property on txtCustomer_name = line
Why? and how can I solve it ?
You can try this:
If IsNull(recSet.Fields("Customer_name").Value) Then
txtCustomer_name.Text = ""
Else
txtCustomer_name.Text = recSet.Fields("Customer_name").Value
End If

Resources