search the database and put it in textbox - visual-studio

Using VB 6 and adodb connection, when I click search for id, a inputbox will appear, when it finds The id I wanted, it will automatically insert all the data of that row to their corresponding textboxes.
Here my code, at somepoint, it does not work, I dont remember the error but I will post it here when I get home, thanks for your help guys.
Private Sub cmdsearch_Click()
findemployee = InputBox("Insert Employee ID")
record.Open ("select * from employees where ID='" & findemployee & "'"), conn, 3, 3
If record.EOF Then
MsgBox "NO" & findemployee & " ID WAS NOT FOUND!", vbCritical + vbOKOnly, "Error Search"
Set record = Nothing
Else
txtemployeeid.Text = record!ID
txtlnames.Text = record!lastname
txtfnames.Text = record!Firstname
txtmnames.Text = record!middlename
cmbgenders.Text = record!gender
bdates.Value = record!birthdate
txtbplaces = record!birthplace
txtages = record!age
txtaddress.Text = record!address
cmbeducattainments.Text = record!educattainment
txtnos.Text = record!contactno
cstarts.Value = record!contractstart
cends.Value = record!contractend
Set record = Nothing
End If
End Sub

Private Sub cmdsearch_Click()
findemployee = inputtextbox.text
record.Open ("select * from employees where ID='" & findemployee & "'"), conn, 3, 3
If record.EOF Then
MsgBox "NO" & findemployee & " ID WAS NOT FOUND!", vbCritical + vbOKOnly, "Error Search"
Set record = Nothing
Else
with record
txtemployeeid.Text = !ID
txtlnames.Text = !lastname
txtfnames.Text = !Firstname
txtmnames.Text = !middlename
cmbgenders.Text = !gender
bdates.Value = !birthdate
txtbplaces = !birthplace
txtages = !age
txtaddress.Text = !address
cmbeducattainments.Text = !educattainment
txtnos.Text = !contactno
cstarts.Value = !contractstart
cends.Value = !contractend
Set record = Nothing
END WITH
End If
End Sub

Related

adding data to oracle database in vb6

I have a problem adding data oracle database,it's show me this message(" https://ufile.io/lzpuj ") Run-time ORA-00904:"EMPCODE": invalid identifier.
This is Cody:
Dim connEmp As ADODB.Connection
Dim rsEmp As ADODB.Recordset
Private Sub Command1_Click()
Set rsEmp = New ADODB.Recordset
rsEmp.Open "select * from tablebooks where empcode = '" & Text1.Text & "'",
connEmp, adOpenKeyset, adLockReadOnly, adCmdText
If rsEmp.RecordCount <> 0 Then
MsgBox " ! åÐÇ ÇáßÊÇÈ ãæÌæÏ ÈÇáÝÚá "
rsEmp.Close
Set rsEmp = Nothing
Exit Sub
Else
Set rsEmp = New ADODB.Recordset
rsEmp.Open "select * from tablebooks where empcode = '" & Text1.Text & "'",
connEmp, adOpenKeyset, adLockPessimistic, adCmdText
rsEmp.AddNew
rsEmp!Book_no = Val(Trim(Text1.Text))
rsEmp!Book_name = Trim(Text2.Text)
rsEmp!Author_name = Trim(Text10.Text)
rsEmp!Edition_no = Val(Trim(Text3.Text))
rsEmp!Publisher_place = Trim(Text11.Text)
rsEmp!Part_no = Val(Trim(Text5.Text))
rsEmp!Book_cost = Trim(Text6.Text)
rsEmp!Place_book = Trim(Text7.Text)
rsEmp!Note = Trim(Text9.Text)
rsEmp!Date_publishing = DTPicker1.Value
rsEmp!Subject = Trim(Combo4.Text)
rsEmp!State = Trim(Combo4.Text)
rsEmp.Update
connEmp.Execute "commit"
rsEmp.Close
Set rsEmp = Nothing
Label11.Visible = True
Label11 = " ! ÊãÊ ÇáÅÖÇÝÉ ÈäÌÇÍ "
End If
End Sub
First make sure empcode is exactly the right column name.
Then fix your code. You have two big issues:
It's crazy-vulnerable to Sql Injection attacks.
It tries to re-open the same command on the same connection in the ELSE block for no reason.
The exact fix for #1 depends on which provider you are using (Ole vs Odbc), but this link might help:
Call a parameterized Oracle query from ADODB in Classic ASP
For #2, this is somewhat better:
Dim connEmp As ADODB.Connection
Dim rsEmp As ADODB.Recordset
Private Sub Command1_Click()
Set rsEmp = New ADODB.Recordset
'TODO: Use parameterized query here!
rsEmp.Open "select * from tablebooks where empcode = #empcode '" & Text1.Text & "'",
connEmp, adOpenKeyset, adLockReadOnly, adCmdText
If rsEmp.RecordCount <> 0 Then
MsgBox " ! åÐÇ ÇáßÊÇÈ ãæÌæÏ ÈÇáÝÚá "
rsEmp.Close
Set rsEmp = Nothing
Exit Sub
End If
rsEmp.AddNew
rsEmp!Book_no = Val(Trim(Text1.Text))
rsEmp!Book_name = Trim(Text2.Text)
rsEmp!Author_name = Trim(Text10.Text)
rsEmp!Edition_no = Val(Trim(Text3.Text))
rsEmp!Publisher_place = Trim(Text11.Text)
rsEmp!Part_no = Val(Trim(Text5.Text))
rsEmp!Book_cost = Trim(Text6.Text)
rsEmp!Place_book = Trim(Text7.Text)
rsEmp!Note = Trim(Text9.Text)
rsEmp!Date_publishing = DTPicker1.Value
rsEmp!Subject = Trim(Combo4.Text)
rsEmp!State = Trim(Combo4.Text)
rsEmp.Update
connEmp.Execute "commit"
rsEmp.Close
Set rsEmp = Nothing
Label11.Visible = True
Label11 = " ! ÊãÊ ÇáÅÖÇÝÉ ÈäÌÇÍ "
End Sub

I can not get result every time I run data report . How can I fix this ?

I want to make a report of daily income expense account. I am using a data environment for this report and made date field as group field. The problem is that every time I run the program the data sometimes appears and sometime it's showing just blank. I can't understand why this is happening and what is the reason for it?
I have bind table directly through data environment tool
code is here
Private Sub CmdOk_Click()
Dim RsRojmelIncome As New ADODB.Recordset
Dim RsRojmelExp As New ADODB.Recordset
Dim RsTempRojmel As New ADODB.Recordset
cn.Execute "delete from TempRojmel"
RsRojmelIncome.Open " select * from Rojmel where Date1 BETWEEN #" & Format(DTPicker1.Value, "MM/DD/yyyy") & "# AND #" &
Format(DTPicker2.Value, "MM/DD/YYYY") & "# And IncExp = 'ytJtf'", cn,
adOpenKeyset, adLockOptimistic
RsRojmelExp.Open " select * from Rojmel where Date1 BETWEEN #" & Format(DTPicker1.Value, "MM/DD/yyyy") & "# AND #" &
Format(DTPicker2.Value, "MM/DD/YYYY") & "# And IncExp = 'SJtf'", cn,
adOpenKeyset, adLockOptimistic
Set RsTempRojmel = New ADODB.Recordset
RsTempRojmel.Open "Select * from TempRojmel", cn, adOpenKeyset, adLockOptimistic
If RsRojmelIncome.RecordCount >= 1 Then
For i = 1 To RsRojmelIncome.RecordCount RsTempRojmel.AddNew RsTempRojmel.Fields("Id") = i RsTempRojmel.Fields("IncVigat") =
RsRojmelIncome.Fields("Vigat") RsTempRojmel.Fields("Date1") =
RsRojmelIncome.Fields("Date1") RsTempRojmel.Fields("IncAmount") =
RsRojmelIncome.Fields("Amount") RsTempRojmel.Update
RsRojmelIncome.MoveNext
Next i
End If
If RsRojmelExp.RecordCount >= 1 Then
For j = 1 To RsRojmelExp.RecordCount RsTempRojmel.AddNew RsTempRojmel.Fields("Id") = j RsTempRojmel.Fields("ExpVigat") =
RsRojmelExp.Fields("Vigat") RsTempRojmel.Fields("Date1") =
RsRojmelExp.Fields("Date1") RsTempRojmel.Fields("ExpAmount") =
RsRojmelExp.Fields("Amount") RsTempRojmel.Update
RsRojmelExp.MoveNext
Next j
End If
If DataEnvironment1.rsCommand1_Grouping.State = 0 Then
DataEnvironment1.rsCommand1_Grouping.Open " SHAPE {SELECT * FROM TempRojmel} AS Command1 COMPUTE Command1, SUM(Command1.'IncAmount')
AS Aggregate1, SUM(Command1.'ExpAmount') AS Aggregate2,CALC
(Aggregate1-Aggregate2) as NetProf1 BY 'Date1' ",
DataEnvironment1.Connection1, adOpenKeyset, adLockOptimistic
End If
RptRojmel.Sections("Section7").Controls.Item("Text1").DataField = DataEnvironment1.rsCommand1_Grouping.Fields("NetProf1").Name
RptRojmel.Sections("Section7").Controls.Item("Text2").DataField = DataEnvironment1.rsCommand1_Grouping.Fields("Aggregate1").Name
RptRojmel.Sections("Section4").Controls.Item("LblDate1").Caption = DTPicker1.Value
RptRojmel.Sections("Section4").Controls.Item("LblDate2").Caption = DTPicker2.Value
RptRojmel.Refresh
DataEnvironment1.rsCommand1_Grouping.Requery
RptRojmel.Refresh
End Sub
instead of
If DataEnvironment1.rsCommand1_Grouping.State = 0 Then
DataEnvironment1.rsCommand1_Grouping.Open " SHAPE {SELECT * FROM TempRojmel} AS Command1 COMPUTE Command1, SUM(Command1.'IncAmount') AS Aggregate1, SUM(Command1.'ExpAmount') AS Aggregate2,CALC (Aggregate1-Aggregate2) as NetProf1 BY 'Date1' ", DataEnvironment1.Connection1, adOpenKeyset, adLockOptimistic
End If
try Using
If DataEnvironment1.rsCommand1_Grouping.State = adStateOpen Then
DataEnvironment1.rsCommand1_Grouping.Close
End If
DataEnvironment1.rsCommand1_Grouping.Open " SHAPE {SELECT * FROM TempRojmel} AS Command1 COMPUTE Command1, SUM(Command1.'IncAmount') AS Aggregate1, SUM(Command1.'ExpAmount') AS Aggregate2,CALC (Aggregate1-Aggregate2) as NetProf1 BY 'Date1' ", DataEnvironment1.Connection1, adOpenKeyset, adLockOptimistic

Pop up alert vb 6

Can someone help me. I'm having a hard time with this. All I need is to display an alert message whenever the medicines expired.My problem is when I got two or more expired medicines it doesn't alert all.Instead it alerts one medicine.Please help.
here is my code
Private Sub Form_Activate()
On Error Resume Next
With Main
.Text4 = Adodc1.Recordset.Fields("MedicineName")
.Text1.Text = Adodc1.Recordset.Fields("genericname")
.Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
.Combo3 = Adodc1.Recordset.Fields("Expmonth")
.Combo4 = Adodc1.Recordset.Fields("Expday")
.Combo5 = Adodc1.Recordset.Fields("Expyear")
End With
Dim expirationdate As Date
expirationdate = CDate(Combo3 & "/" & Combo4 & "/" & Combo5)
datepicker.Value = Format(Now, "MMM-DD-yyyy")
If datepicker > expirationdate Then
MsgBox Text4.Text & " is expired ", vbExclamation, "Warning!"
If MsgBox("Do you want to dispose " & Text4 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc1.Recordset.Delete
ElseIf vbNo Then
Exit Sub
End If
End If
End Sub
Private Sub Form_Load()
Adodc1.CommandType = adCmdUnknown
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\clinic.mdb" & ";Persist Security Info=False"
Adodc1.RecordSource = "select * from inventory order by Expyear asc"
Adodc1.Refresh
Adodc1.Refresh
End sub
You need to loop through all of the records in your recordset. Currently, you're operating on the FIRST record only.
Do Until Adodc1.Recordset.EOF
' Assign values to textboxes, test date, etc.
' Fetch the next record...
Adodc1.Recordset.MoveNext
Loop
Bond is correct, you need to iterate over your recordset to display the message for each record that is expired.
Private Sub Form_Activate()
Dim expirationdate As Date
On Error Resume Next '<-- this is going to cause a problem if you never check for errors
Adodc1.Recordset.MoveFirst 'make sure the control is positioned on the first record
Do While Adodc1.Recordset.EOF = False 'loop over all of the records
With Main
.Text4.Text = Adodc1.Recordset.Fields("MedicineName")
.Text1.Text = Adodc1.Recordset.Fields("genericname")
.Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
.Combo3 = Adodc1.Recordset.Fields("Expmonth")
.Combo4 = Adodc1.Recordset.Fields("Expday")
.Combo5 = Adodc1.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo3 & "/" & Combo4 & "/" & Combo5)
datepicker.Value = Format(Now, "MMM-DD-yyyy")
If datepicker > expirationdate Then
MsgBox Text4.Text & " is expired ", vbExclamation, "Warning!"
If MsgBox("Do you want to dispose " & Text4 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc1.Recordset.Delete
End If
End If
Adodc1.Recordset.MoveNext
Loop
End Sub

Duplicate error in current scope vb 6

Can someone help me. I'm trying to display an alert msgbox with two different recordset in one form so whenever there is an expired medicine it will both display and alert at the same time. But it gives me an error "Duplicate error in current scope"
In this line
Dim expirationdate As Date
Do While Not Adodc2.Recordset.EOF = True
'----------'
Private Sub Form_Activate()
Dim expirationdate As Date
Me.AutoRedraw = True
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF = True
With Main
.Text4.Text = "" & Adodc1.Recordset.Fields("MedicineName")
.Text1.Text = Adodc1.Recordset.Fields("genericname")
.Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
.Combo3.Text = Adodc1.Recordset.Fields("Expmonth")
.Combo4.Text = Adodc1.Recordset.Fields("Expday")
.Combo5.Text = Adodc1.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo3 & "/" & Combo4 & "/" & Combo5)
datepicker.Value = Format(Now, "MMM-DD-yyyy")
If datepicker > expirationdate Then
MsgBox Text4.Text & " is Expired! ", vbExclamation, "Warning"
If MsgBox("Do you want to dispose " & Text4 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc1.Recordset.Delete
Else
Exit Sub
End If
End If
Adodc1.Recordset.MoveNext
Loop
'________________'
Dim expirationdate As Date
Me.AutoRedraw = True
Adodc2.Recordset.MoveFirst
Do While Not Adodc2.Recordset.EOF = True
With Main
.Text10 = Adodc2.Recordset.Fields("roomno")
.Text11 = "" & Adodc2.Recordset.Fields("MedicineName")
.Text2 = Adodc2.Recordset.Fields("GenericName")
.Text12.Text = Adodc2.Recordset.Fields("StockQuantity")
.Combo10 = Adodc2.Recordset.Fields("Expmonth")
.Combo11 = Adodc2.Recordset.Fields("Expday")
.Combo12 = Adodc2.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo10 & "/" & Combo11 & "/" & Combo12)
datepicker2.Value = Format(Now, "MMM-DD-yyyy")
If datepicker2 < expirationdate Then
MsgBox "OK!", vbInformation, "Working"
Else
MsgBox "Medicine Expired!.", vbExclamation, " Warning!"
If MsgBox("Do you want to delete " & Text11 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc2.Recordset.Delete
Exit Sub
End If
End If
Adodc2.Recordset.MoveNext
Loop
End Sub
Try this. You are sometimes relying on the default properties of your controls. This is generally bad, so I added the properties. I also removed the Exit Sub line. If the user clicks No you don't want to exit the sub, you want to continue looping through the Adodc2 Recordset.
Me.AutoRedraw = True
Adodc2.Recordset.MoveFirst
Do While Not Adodc2.Recordset.EOF = True
With Main
.Text10.Text = Adodc2.Recordset.Fields("roomno")
.Text11.Text = "" & Adodc2.Recordset.Fields("MedicineName")
.Text2.Text = Adodc2.Recordset.Fields("GenericName")
.Text12.Text = Adodc2.Recordset.Fields("StockQuantity")
.Combo10.Text = Adodc2.Recordset.Fields("Expmonth")
.Combo11.Text = Adodc2.Recordset.Fields("Expday")
.Combo12.Text = Adodc2.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo10.Text & "/" & Combo11.Text & "/" & Combo12.Text)
datepicker2.Value = Format(Now, "MMM-DD-yyyy")
If datepicker2.Value < expirationdate Then
MsgBox "OK!", vbInformation, "Working"
Else
MsgBox "Medicine Expired!.", vbExclamation, " Warning!"
If MsgBox("Do you want to delete " & Text11.Text & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc2.Recordset.Delete
End If
End If
Adodc2.Recordset.MoveNext
Loop

VBScript SMTP Server

I have set this up to auto email through the Outlook client, is it possible to change this code to work directly through an SMTP server? And could anyone possibly help me do it?
Any help would be much appreciated, thanks!
Set app = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
For Each f In fso.GetFolder("Y:\Billing_Common\autoemail").Files
If LCase(fso.GetExtensionName(f)) = "xls" Then
Set wb = app.Workbooks.Open(f.Path)
set sh = wb.Sheets("Auto Email Script")
row = 2
name = "Customer"
email = sh.Range("A" & row)
subject = "Billing"
the = "the"
LastRow = sh.UsedRange.Rows.Count
For r = row to LastRow
If App.WorkSheetFunction.CountA(sh.Rows(r)) <> 0 Then
SendMessage email, name, subject, TRUE, _
NULL, "Y:\Billing_Common\autoemail\Script\energia-logo.gif", 143,393
row = row + 1
email = sh.Range("A" & row)
End if
Next
wb.Close
End If
Next
Sub SendMessage(EmailAddress, DisplayName, Subject, DisplayMsg, AttachmentPath, ImagePath, ImageHeight, ImageWidth)
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
template = FindTemplate()
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(EmailAddress)
objOutlookRecip.resolve
objOutlookRecip.Type = 1
' Set the Subject, Body, and Importance of the message.
.Subject = Subject
.bodyformat = 3
.Importance = 2 'High importance
body = Replace(template, "{First}", name)
body = Replace(body, "{the}", the)
if not isNull(ImagePath) then
if not ImagePath = "" then
.Attachments.add ImagePath
image = split(ImagePath,"\")(ubound(split(ImagePath,"\")))
body = Replace(body, "{image}", "<img src='cid:" & image & _
"'" & " height=" & ImageHeight &" width=" & ImageWidth & ">")
end if
else
body = Replace(body, "{image}", "")
end if
if not isNull(AttachMentPath) then
.Attachments.add AttachmentPath
end if
.HTMLBody = body
.Save
.Send
End With
Set objOutlook = Nothing
End Sub
Function FindTemplate()
Set OL = GetObject("", "Outlook.Application")
set Drafts = OL.GetNamespace("MAPI").GetDefaultFolder(16)
Set oItems = Drafts.Items
For Each Draft In oItems
If Draft.subject = "Template" Then
FindTemplate = Draft.HTMLBody
Exit Function
End If
Next
End Function
If you want to send mail directly to an SMTP server, there's no need to go through Outlook in the first place. Just use CDO. Something like this:
schema = "http://schemas.microsoft.com/cdo/configuration/"
Set msg = CreateObject("CDO.Message")
msg.Subject = "Test"
msg.From = "sender#example.com"
msg.To = "recipient#example.org"
msg.TextBody = "This is some sample message text."
With msg.Configuration.Fields
.Item(schema & "sendusing") = 2
.Item(schema & "smtpserver") = "smtp.intern.example.com"
.Item(schema & "smtpserverport") = 25
.Update
End With
msg.Send

Resources