Searching Data from DataGrid Control using ADODC in VB6.0 - visual-studio

I'm a student doing my final year mini project and am facing a problem related to searching data in the datagrid.
The error I'm getting is :
Run-time error : '3001'
Arguments are of wront type, are out of acceptable range, or are in conflict with one another
The code is :
Private Sub Command1_Click()
Dim item As String
Adodc1.Recordset.MoveFirst
item = Text1.Text
Adodc1.Recordset.Find "L_No = " & item
If Adodc1.Recordset.EOF Then
MsgBox "Record Set not found"
End If
End Sub
The above code is working when the data I'm searching is only number.
For example
When I search the data on the basis of L_Id which is a License ID an Integer value the searching is done and I'm getting the result.
When I search the data on the basis of L_No which is a License Number a string value which consists of both numbers and alphabets I'm getting the above error.
Do I have to parse the value is text1.text or do anything else?

When the field you're searching in is not a numeric type, you'll want to delimit it with single quotes:
Adodc1.Recordset.Find "L_No = '" & item & "'"

Related

Accept a name in Text Box, Print it when someone click on Print Button

I have a TextBox in VB and a Command Button. I want to print the string upon clicking on command button.
I am using the following code, please tell what I am doing wrong:-
Dim name As String
name = Val(Text1.Text)
MsgBox ("Welcome" & Str(name))
When I input a string in Textbox and click on command button, result is:
Welcome 0
Leave out the val() around your Text1.Text, val() returns the numbers up to the first symbol it can't recognize as a number used in a String. See the documentation. I guess you used a 0 in your string in the TextField or no number at all, both would return 0.
Additionally, it is unnecessary to cast your String name to a String since it is already a String so you can also leave out the Str().
The val function returns the numeric representation of its argument, otherwise it returns "0". It's a bit hard these days to find the official VB6 documentation, but you may want to check: https://en.wikibooks.org/wiki/Visual_Basic/VB6_Command_Reference#Val
So, in your example, if you enter any number in the Text1 textbox control, you will see it in your message box. If you enter any text, you will get "Welcome 0", as you do now. Therefore, you have to remove the val function from your code, like:
Dim name As String
name = Text1.Text
MsgBox ("Welcome " & name)
maybe even simplifying it to:
MsgBox("Welcome " & Text1.Text)
So you declared a string varaible namewhich you want to fill with the text from the Text1box. So you need to spare the val(...)part.
Second, as namealready represents a string, leave out the strin the message box:
name = Text1.Text
MsgBox ("Welcome " & name)

Fill down formula in column gives 400 error

I am going to be splitting an incorrect url string in a column and need to use a formula to split it into separate columns. I have an empty column "H" next to column "G" which holds the incorrect url strings. Below you will see that I am trying to set "leftURL" to a formula and then copy it down the entire column. This works fine using regular Excel but when I try to do it as VBScript I get a 400 error:
Sub formulaLeft()
Worksheets("Feed Original").Activate
Dim lngLastRow As Long
Dim leftURL As Variant
leftURL = "=IF(ISNUMBER(SEARCH('%20',G2)),(LEFT(G2,FIND('%20',G2)-1)),G2)"
Sheets("Feed Original").Range("H2").Value = leftURL
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("H2:H" & lngLastRow).Value = leftURL
End Sub
What am I doing wrong?

visual basic 6 access 2007 database programming cascading combo boxes

I have a table named: schoolInfo in access 2007 and it has two fields (schName and mjrName).
Now I'm trying to design a combo in Visual Basic 6 (cboMajors) which is related to the other combo (cboSchool).
As a matter of fact I want to have to cascading combo boxes. When I choose an Item in cboSchool the other combo should represents just the related majors for that school (records with schName=x and mjrName=y).
Private Sub Form_Activate()
connection
' the Connection is a code in module contains codes are needed to make the connection between form and the database
fill_schools
fill_majors
End Sub
Also,
Private Sub fill_schools()
With rs
.Open "select DISTINCT schName from tblSchoolsInfo", cn, 2, 3
Do While Not .EOF
cboSchool.AddItem (.Fields(0))
.MoveNext
Loop
End With
rs.Close
End Sub
Private Sub fill_majors()
With rs
.Open "select DISTINCT mjrName from tblSchoolsInfo where schName= '" & Me.cboSchool & " '", cn, 2, 3
Do While Not .EOF
cboMajors.AddItem (.Fields(0))
.MoveNext
Loop
End With
End Sub
Now: the first combo get correct values but the second one is completely empty.
In the snippet of code you have given us, I can't see anywhere where you actually select the school in Form_Activate(). This means that by the end of that procedure, there will be no selection in school, so fill_majors() will execute:
select DISTINCT mjrName from tblSchoolsInfo where schName= ' '
Incidentally, is that trailing space deliberate? In which case, this won't return records even if a school is selected.
The OP solved this in dreamincode.net. He was tacking an extra space on the end of his combo box string: Me.cboSchool & " '"
I've always wanted to say this: "This behavior is by design." :)
just a suggestion did you check the
cboMajors.AddItem (.Fields(0)) <--- .Fields()

How to Find Record Set Value is Number or String?

Original:
Using VB6
If rsCardEvent(4).Value = Str Then
TimOut = rsCardEvent(4)
Else
TimeOut = Left(TimOut, 2) & ":" & Mid(TimOut, 3, 2) & ":" & Right(TimOut, 2)
End If
Getting Type MisMatch Error.
How To Find Record Set Value is String or Number
Exactly i need
If Number means print number like Time Format (HH:MM:SS)
else
print string value
Coding Help for the above condition
Edited Version:
I'm working with an ADO.Recordset object and am trying to determine the data type of a column at run-time. I need to handle the column value differently in my code depending on its underlying data type. If the column value is a string, I want to work with the value as-is. If it is a number, I want to treat the number as an packed time and convert it to HH:MM:SS format (i.e. the number 120537 would be converted to the string "12:05:37").
Below is some example code that demonstrates what I want to achieve. However, when I run this code I get a "Type Mismatch" error:
If rsCardEvent(4).Value = Str Then
TimOut = rsCardEvent(4)
Else
TimeOut = Left(TimOut, 2) & ":" & Mid(TimOut, 3, 2) & ":" & Right(TimOut, 2)
End If
Have a look at the Visual Basic 6 function library. There are functions that can help you determine the underlying type of a value.
There are quite a few but you might find these useful:
IsNumeric
IsDate
Based on this article, if rsCardEvent is an ADO recordset, you could check the Type property. Something like this:
Select Case rsCardEvent(4).Type
Case adBSTR, adChar, adVarChar, adWChar, _
adVarWChar, adLongVarChar, adLongVarWChar
' It is a string '
Case Else
' It is not a string '
End Select
You can use the IsNumeric function available in VB6.
How about:
If TypeName(rsCardEvent(4).Value) = "String" then
http://msdn.microsoft.com/en-us/library/5422sfdf.aspx

Full Search testing in LINQ (custom filter query)

I have a table that has a list of restaurant names and links to another table that holds the cuisine type.
I want to provide a search box on my web page that when typing, each word is searched for in the database and results returned. I was looking for a solution that doesn't involve setting up sql full text search as I want to be able to test this using Linq to SQL.
From my old code I have a function which creates a query filter given the input text and returns all the results based on that.
Private Function SetupQuery(ByVal searchText As String) As String
Dim searchFields As New List(Of String)
searchFields.Add("Name")
searchFields.Add("Postcode")
searchFields.Add("Cuisine")
Dim firstCol As Boolean = True
Dim a() As String
Dim j As Integer
a = searchText.Trim.Split(" ")
Dim filter As String = ""
Dim compareString As String
For Each col As String In searchFields
For j = 0 To a.GetUpperBound(0)
compareString = a(j).ToUpper()
compareString = compareString.Trim()
If firstCol Then
filter = filter & col & " LIKE '" & compareString & "%' "
firstCol = False
Else
filter = filter & " or " & col & " LIKE '" & compareString & "%' "
End If
Next
Next
Return filter
End Function
This has the search fields hard coded and then loops through each one and each word in the search text to construct an OR LIKE filter.
I'm sure I could then use this in my LINQ code but it doesn't seem like an elegant solution especially since the columns are hard coded and not used how LINQ uses them.
Could anyone recomend a better way to do this or some tips in what direction to go with this?
Thanks
I don't how know this will affect your testing, but LinqtoSQL can be made to work with full-text indexing with a few wiggles:
LinqToSql and full text search - can it be done?
http://sqlblogcasts.com/blogs/simons/archive/2008/12/18/LINQ-to-SQL---Enabling-Fulltext-searching.aspx
You could use full text search and still use LINQ to SQL. You can create a stored procedure and have LINQ call it. In addition to finding exact matches you could return:
Simple searches for specific words or phrases
Thesaurus searches for synonymous forms of word – a search on IE might return hits to Internet Explorer and IE (thesaurus based expansion search); a search on Bombay might also return hits to Mumbai (thesaurus based replacement search)
Searches that will return all different linguistic forms of a word (called generations) search on bank would return hits to banking, banked, banks, banks' and bank's, etc. (all declensions and/or conjugations of the search term bank)
Accent insensitive searches – a search on café would return hits to cafe and café
http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
http://www.simple-talk.com/sql/learn-sql-server/sql-server-full-text-search-language-features/
This probably isn't the best way to do this, but if you're always getting the search text as string split into an array of three then you could try using this:
from t in temp
where t.Name == a(0)
|| t.Postcode == a(1)
|| t.Cuisine == a(2)
select t
I normally do C#, so naturally anything in VB scares, but I think the LINQ syntax should be similar

Resources