how can i add VB6 Adodc.recordset.find - vb6

I'm trying to search and display my database on textbox using VB6, but im not quite sure where the problem is,how would i display my data base in textboxes after i search for it?
I've aldready tried different set of codes but none seems to work. i've also tried the inputbox.
Dim search As String
search = Text5.Text
Adodc1.Recordset.Find "Studno = " & search
If Adodc1.Recordset.EOF Then
MsgBox "NO record"
Else
Adodc1.Recordset.Fields("Studno") = Text1.Text
Adodc1.Recordset.Fields("Studname") = Text2.Text
Adodc1.Recordset.Fields("Age") = Text3.Text
Adodc1.Recordset.Fields("Address") = Text4.Text
End If
i would like to display all the fields in the textboxes after i searched for the studno.

You're trying to add the content of the textboxes to the recordset fields rather than the other way round. Try:
Text1.Text = Adodc1.Recordset.Fields("Studno")
Text2.Text = Adodc1.Recordset.Fields("Studname")
Text3.Text = Adodc1.Recordset.Fields("Age")
Text4.Text = Adodc1.Recordset.Fields("Address")

Ok. Updated answer. Try:
Adodc1.Recordset.Find "Studno = '" & search & "'"
and put a breakpoint on the first line after the Else statement to make sure it's getting that far. (Note there is a single quote both before and after the search string.)
You'll still need the changes I posted originally to actually see the results.

Related

VBScript text Formatting issues

I have data that has <br> and <BR> Tags in it. I have to update a old site that is running VBScript Classic ASP. I know little to nothing about either of these two but i came up with some hackish logic to try and quickly resolve the problem and i do not understand why it is not working.
If InStr(1,objRecN("News"),"<BR>")> 1 Then
response.write "This is 1<BR>"
body = Replace(objRecN("News"),"<BR>", vbCrLf)
Else
response.write "This is 2<br>"
body = Replace(objRecN("News"),"<br>", vbCrLf)
End If
The Response.Writes are working effectively in proving that the right logic is being applied but the replace is not working.
body = Replace(Replace(objRecN("News"),"<br>", vbCrLf), "<BR>", vbCrLf)
Also this is not working. This was my first attempt at trying to resolve this. Any clues?
As soon as other logic is applied it breaks!
If InStr(1,objRecN("News"),"<BR>")> 1 Then
response.write "This is 1<BR>"
body = Replace(objRecN("News"),"<BR>", vbCrLf )
End If
All hard info (c) #Alex.
VBScript's Replace function works; it can even be asked to ignore case (mark the use of pre-defined vbTextCompare instead of magic number). If it does not seem so, the programmer is to blame. Evidence:
>> s = "abc<br>def<BR>ghi"
>> WScript.Echo qq(s)
>> s = Replace(s, "<br>", "!!!!", 1, -1, vbTextCompare)
>> WScript.Echo qq(s)
>>
"abc<br>def<BR>ghi"
"abc!!!!def!!!!ghi"
If you replace with vbCrLf (or other whitespace) and then write the result to HTML, you won't 'see' the hard work Replace did for you.
If you insist on two (or more) replacements, you have to feed the previous result to the current operation. That's why your
body = Replace(objRecN("News"),"<BR>", vbCrLf)
body = Replace(objRecN("News"),"<br>", vbCrLf)
'work' separately but not together. In contrast, both
body = objRecN("News")
body = Replace(body,"<BR>", vbCrLf)
body = Replace(body,"<br>", vbCrLf)
or
body = Replace(Replace(objRecN("News"),"<br>", vbCrLf), "<BR>", vbCrLf)
will deal with all <BR> and <br>, but not with <Br>, which is no problem for the vbTextCompare version.
If you next data contain <br/>, <br />, and <br />, you'll need a regular expression.
Thank you everyone for your help.
body = Replace(body,"<BR>", "<br>")
Although i learned a lot from your posts. This is the code that actually fixed my problem. I am sorry if i didn't not convey it better.

Excel VBA Outlook / Mail functions requires recalculation or sets all formulas to #Value

I'll try to keep it short and precise.
I really hope you can help me.
I am facing the following problem:
Background:
Workbook with a lot of formulas -> Calculation set to manual
Recalculation takes 5-10 minutes each time
What I want to do:
Generate ranges of data individually for multiple people
then select those ranges, and paste them into the body of an e-mail
send those e-mails one by one
What is the problem?
If I use the "Envelope" method to prepare the e-mails everything is fine until I press send. However, every time I press send excel automatically recalculates the entire Workbook. Obviously I do not want to wait 5-10 minutes to send out each e-mail (always between 10 and 20)
Since I thought it might have to do with the "Envelope" method I decided to switch to creating an e-mail directly via Outlook (outlook object). It worked fine as far as opening the e-mail and sending it without recalculation. However, after the e-mail is opened by Outlook, all(!) formulas in the entire Workbook are set to #Value. This obviously also forces me to recalculate as I cannot create the table for the next person's e-mail.
Does anyone know what is causing the recalculation/error values and what I can do to stop it? I'd be really glad about any suggested solutions.
I am also attaching my code, though I doubt it will help in clearing up the issue
`'DESCRIPTION:
'This routine prepares an e-mail for requesting the progress estimates from the deliverable owners
'1. set all the values based on named ranges in PI and Config sheets
'2. Concatenate all relevant strings to full e-mail text
'3. select PI table
'4. Create e-mail and display
Sub PrepareEmail()
Dim s_EmailAddress As String, s_FirstName As String
Dim s_Email_Greeting As String, s_Email_MainText1 As String, s_Email_MainText2 As String, s_Email_DeadlineRequest As String
Dim s_Email_Deadline As String, s_Email_Subject As String, s_Email_ClosingStatement As String, s_Email_SenderName As String, s_Email_CC As String
Dim s_Email_Full As String
Dim rng_PI_TableValues As Range, rng_PI_TableFull As Range
Dim s_Email_FullText As String
Dim obj_OutApp As Object
Dim obj_OutMail As Object
s_EmailAddress = [ptr_PI_Email]
s_FirstName = [ptr_PI_FirstName]
s_Email_Subject = [ptr_Config_PIEmail_Subject]
s_Email_Greeting = [ptr_Config_PIEmail_Greeting]
s_Email_MainText1 = [ptr_Config_PIEmail_MainText1]
s_Email_MainText2 = [ptr_Config_PIEmail_MainText2]
s_Email_DeadlineRequest = [ptr_Config_PIEmail_DeadlineRequest]
s_Email_Deadline = [ptr_Config_PIEmail_Deadline]
s_Email_ClosingStatement = [ptr_Config_PIEmail_ClosingStatement]
s_Email_SenderName = [ptr_Config_PIEmail_SenderName]
s_Email_CC = [ptr_Config_PIEmail_CC]
'Concatenate full e-mail (using HTML):
s_Email_Full = _
"<basefont face=""Calibri"">" _
& s_Email_Greeting & " " _
& s_FirstName & ", " & "<br> <br>" _
& s_Email_MainText1 & "<br>" _
& s_Email_MainText2 & "<br> <br>" _
& "<b>" & s_Email_DeadlineRequest & " " _
& s_Email_Deadline & "</b>" & "<br> <br>" _
& s_Email_ClosingStatement & "," & "<br>" _
& s_Email_SenderName _
& "<br><br><br>"
'-------------------------------------------------------
Set rng_PI_TableValues = Range("tbl_PI_ProgressInput")
Set rng_PI_TableFull = Union(rng_PI_TableValues, Range("tbl_PI_ProgressInput[#Headers]"))
Application.EnableEvents = False
Application.ScreenUpdating = False
Set obj_OutApp = CreateObject("Outlook.Application")
Set obj_OutMail = obj_OutApp.CreateItem(0)
With obj_OutMail
.To = s_EmailAddress
.CC = s_Email_CC
.Subject = s_Email_Subject
.HTMLBody = s_Email_Full & RangetoHTML(rng_PI_TableFull)
.Display
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
Call update_Status
End Sub
`
If you're using RangeToHTML from Ron de Bruin's website, that's what's causing your problem. That utility is fine if you need perfect fidelity and have a heavily formatted bu otherwise fairly simple range. But if your range has a bunch of dependencies, you'll have problems. It's putting the range into its own workbook, so any formulas that refer to data outside the range get funky.
If you need perfect fidelity, then you're stuck because the only way it will be perfect is by saving the range as HTML and reading that back. But if you don't have a bunch of heavy formatting or you just need a nice looking table, then I suggest you write your own RangeToHTML function that produces the HTML strings.
David McRitchie has some functions that do a pretty good job if you don't want to roll your own. http://dmcritchie.mvps.org/excel/xl2html.htm
Also, I don't know what update_Status does, but if it's causing a recalc, then you have two problems. If that's the case, figure out how to store up all the stuff that update_status does and do it once at the end rather than in the loop.

How to limit the value of the textbox in vb 6.0

I am doing a marks updating database system. I need to limit each of my textbox to be in the value of less than 100, when its over than 100 or when its not number, a message box will pop up and the data won't be save until the user change the mistake. How can I do it?
I agree with Hiren Pandya, but I thought I would add my own take as well.
Be aware that converting a string to a numerical value is not trivial, but the Val, CInt, CDBl etc. functions in VB6 can all give you behavior that close to what you want. (some of those links are for VB.Net, but can still be valuable). You want to make sure you are thinking about digit grouping, positive/negative, decimal separators, etc. when you are validating user input on your own. Most of the time, the built-in functions are good enough.
Private Sub Text1_Change()
On Error GoTo Err_Handler
Dim text As String
text = Text1.text
If IsNumeric(text) = True Then
'If you only want integers...
Dim value As Integer
value = Val(text)
If value <= 100 And value > 0 Then
'The value is good so whatever stuff you need to do
'And then leave the procedure
Exit Sub
End If
End If
'Let everything else fall through here...
Err_Handler:
MsgBox "Invalid input."
'Other stuff to prevent saving
End Sub
In the properties of the text box, set MaxLength to 2.
If you want a message, in the text box Change event, you could do...
If Len(txtBox.Text)>2 then msgbox...
then add your message in the messagebox.
I could go into more detail if you need it. Some thing like below...
Private Sub Text1_Change()
If Len(Text1) > 6 Then
Text1 = " "
MsgBox "Not more than six"
Text1.SetFocus
End If
End Sub

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()

Searching Data from DataGrid Control using ADODC in VB6.0

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 & "'"

Resources