EOF and BOF error when clicking once in listview - vb 2008 - eof

my problem is when i'm clicking a data in my listview i get that error. can anyone help me :(
This is my code
Public Class frmRegister
Sub Clear()
txtID.Text = ""
txtFAN.Text = ""
txtFN.Text = ""
txtMI.Text = ""
txtAD.Text = ""
cboCS.Text = ""
cboSEX.Text = ""
DateTimePicker.Text = ""
txtEDUC.Text = ""
txtEMP.Text = ""
txtPOPD.Text = ""
txtYEARS.Text = ""
txtMONTH.Text = ""
cboProg.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If txtFAN.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtFAN.Focus() : Exit Sub : End If
If txtFN.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtFN.Focus() : Exit Sub : End If
If txtMI.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtMI.Focus() : Exit Sub : End If
If txtAD.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtAD.Focus() : Exit Sub : End If
If cboCS.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : cboCS.Focus() : Exit Sub : End If
If cboSEX.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : cboSEX.Focus() : Exit Sub : End If
If DateTimePicker.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : DateTimePicker.Focus() : Exit Sub : End If
If txtEDUC.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtEDUC.Focus() : Exit Sub : End If
If txtEMP.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtEMP.Focus() : Exit Sub : End If
If txtPOPD.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtPOPD.Focus() : Exit Sub : End If
If txtYEARS.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtYEARS.Focus() : Exit Sub : End If
If txtMONTH.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtMONTH.Focus() : Exit Sub : End If
If MsgBox("Do you want to save this record ?", MsgBoxStyle.YesNo, "Message") = MsgBoxResult.No Then : Exit Sub : End If
rs = New ADODB.Recordset
With rs
If LblAdd_Edit.Text = "Add" Then
.Open("Select * from TableStudents", cn, 3, 3)
.AddNew()
Else
.Open("Select * from TableStudents where No ='" & Me.Text & "'", cn)
End If
.Fields("No").Value = txtID.Text
.Fields("FamName").Value = txtFAN.Text
.Fields("FirstName").Value = txtFN.Text
.Fields("MiddleInitial").Value = txtMI.Text
.Fields("Address").Value = txtAD.Text
.Fields("CivStatus").Value = cboCS.Text
.Fields("Sex").Value = cboSEX.Text
.Fields("BirthDate").Value = DateTimePicker.Text
.Fields("EducAttain").Value = txtEDUC.Text
.Fields("EmpType").Value = txtEMP.Text
.Fields("POPD").Value = txtPOPD.Text
.Fields("NoYears").Value = txtYEARS.Text
.Fields("IncomeMonth").Value = txtMONTH.Text
.Fields("Program").Value = cboProg.Text
.Update()
Clear()
End With
DisplayList()
End Sub
Private Sub frmRegister_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
DisplayList()
End Sub
Private Sub frmRegister_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
connection()
LblAdd_Edit.Text = "Add"
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If MsgBox("Do you want to delete this record ?", MsgBoxStyle.YesNo, "Message") = MsgBoxResult.No Then : Exit Sub : End If
rs = New ADODB.Recordset
rs.Open("select * from TableStudents where No like '" & Me.Text & "'", cn, 3, 3)
rs.Delete()
DisplayList()
End Sub
Private Sub lv1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lv1.MouseClick
'Try
txtID.Enabled = False
rs = New ADODB.Recordset
With rs
.Open("Select * from TableStudents where No Like '" & lv1.FocusedItem.Text & "'", cn, 3, 3)
txtID.Text = .Fields("No").Value
txtFAN.Text = .Fields("FamName").Value
txtFN.Text = .Fields("FirstName").Value
txtMI.Text = .Fields("MiddleInitial").Value
txtAD.Text = .Fields("Address").Value
cboCS.Text = .Fields("CivStatus").Value
cboSEX.Text = .Fields("Sex").Value
DateTimePicker.Text = .Fields("BirthDate").Value
txtEDUC.Text = .Fields("EducAttain").Value
txtEMP.Text = .Fields("EmpType").Value
txtPOPD.Text = .Fields("POPD").Value
txtYEARS.Text = .Fields("NoYears").Value
txtMONTH.Text = .Fields("IncomeMonth").Value
cboProg.Text = .Fields("Program").Value
.MoveNext()
End With
'Catch ex As Exception
'MsgBox(ex.ToString)
'End Try
End Sub
Sub DisplayList()
Dim lst
lv1.Items.Clear()
rs = New ADODB.Recordset
With rs
.Open("select * from TableStudents", cn, 3, 3)
Do While Not .EOF
lst = New ListViewItem
lst = lv1.Items.Add(.Fields("No").Value)
lst.SubItems.Add(.Fields("FamName").Value)
lst.SubItems.Add(.Fields("FirstName").Value)
lst.SubItems.Add(.Fields("MiddleInitial").Value)
lst.SubItems.Add(.Fields("Address").Value)
lst.SubItems.Add(.Fields("CivStatus").Value)
lst.SubItems.Add(.Fields("Sex").Value)
lst.SubItems.Add(.Fields("BirthDate").Value)
lst.SubItems.Add(.Fields("EducAttain").Value)
lst.SubItems.Add(.Fields("EmpType").Value)
lst.SubItems.Add(.Fields("POPD").Value)
lst.SubItems.Add(.Fields("NoYears").Value)
lst.SubItems.Add(.Fields("IncomeMonth").Value)
lst.SubItems.Add(.Fields("Program").Value)
.MoveNext()
Loop
End With
End Sub
Private Sub lv1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lv1.SelectedIndexChanged
Me.Text = lv1.FocusedItem.Text
End Sub
Private Sub btnEDIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEDIT.Click
Me.Text = lv1.FocusedItem.Text
LblAdd_Edit.Text = "Edit"
End Sub
End Class

Related

Error 2501 OpenForm action cancelled

I'm creating two Forms in Access to use as data entry forms. Both are unbound. The data is on assessment "measures" that are part of a standard my company follows. "Measures" is in quotes because a "measure" is often (thought not always) made up of multiple reportable values (called "submeasures" in the specs). That being the case my intent is to use one form is to enter in the portion of data that is related to the "measure", while the other captures the "submeasure" data when needed.
The plan is use a CommandButton to open the Submeasure Form when I need to capture data for a submeasure related to the parent measure. In trying to get that "Add Submeasure" button to work though I keep getting the error mentioned in the title.
Since A) the forms are unbound & B) there's not any data in any of the tables anyway I don't believe that corruption is the issue (which is what this article linked to in another question on RT Error 2501 discusses).
I'm also certain that it's nothing wrong in the Submeasure Form's Form_Load code, since I put a break point on the first line but didn't hit it before getting the error prompt.
The code for the Add Submeasure button follows:
Private Sub New_Sub_Click()
'
'Ensure we have a Key for this measure already NOTE: This Key is associated to each
submeasure so a ListBox can query for it in a table that holds the submeasure data
while I'm doing the data entry
If Me.Msr_Key.Value = "" Then
'notify
MsgBox "New submeasures cannot be created until a Key has been provided for the parent measure.", vbOKOnly, "Unable to Create Submeasures"
Else
'Open the form
DoCmd.OpenForm "New_SubMsr_Form" 'THIS IS THE LINE THAT ERRORS
'Set the form mode & Parent_Key values
Forms![New_SubMsr_Form]![Form_Mode].Value = "New"
Forms![New_SubMsr_Form]![Parent_Key].Value = Me.Msr_Key.Value
'Hide the Msr Form
Me.Visible = False
End If
End Sub
The full code for the New_Msr_Form is below:
Option Compare Database
Private Sub Cancel_Btn_Click()
'
'Clear everything and hide form
Me.Msr_Key.Value = Me.Msr_Key.DefaultValue
Me.Measure_Name.Value = Me.Measure_Name.DefaultValue
Me.Spec_Section.Value = Me.Spec_Section.DefaultValue
Me.Spec_Year_Created.Value = Me.Spec_Year_Created.DefaultValue
Me.Complexity.Value = Me.Complexity.DefaultValue
Me.Inc_Amb.Value = Me.Inc_Amb.DefaultValue
Me.Inc_Medicaid.Value = Me.Inc_Medicaid.DefaultValue
Me.Inc_Medicare.Value = Me.Inc_Medicare.DefaultValue
DoCmd.Close acForm, Me.Name
End Sub
Private Sub Form_Load()
'
'Restore defaults
Me.Msr_Key.Value = Me.Msr_Key.DefaultValue
Me.Measure_Name.Value = Me.Measure_Name.DefaultValue
Me.Spec_Section.Value = Me.Spec_Section.DefaultValue
Me.Spec_Year_Created.Value = Me.Spec_Year_Created.DefaultValue
Me.Complexity.Value = Me.Complexity.DefaultValue
Me.Inc_Amb.Value = Me.Inc_Amb.DefaultValue
Me.Inc_Medicaid.Value = Me.Inc_Medicaid.DefaultValue
Me.Inc_Medicare.Value = Me.Inc_Medicare.DefaultValue
End Sub
Private Sub Inc_Amb_Click()
'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Inc_Amb)
End Sub
Private Sub Inc_Medicaid_Click()
'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Inc_Medicaid)
End Sub
Private Sub Inc_Medicare_Click()
'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Inc_Medicare)
End Sub
Private Sub Denom_Only_Click()
'
'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Denom_Only)
End Sub
Private Sub Msr_Key_AfterUpdate()
'
Dim RowSrc_Str As String
'Is the field empty?
If Me.Msr_Key.Value = "" Or IsNull(Me.Msr_Key.Value) Then
'Make sure the row source is empty
RowSrc_Str = vbNullString
Else
'Populate the Row source string
RowSrc_Str = "SELECT Temp_SubMsrs.ID" & _
" , Temp_SubMsrs.Submeasure Name" & _
" , Temp_SubMsrs.Key" & _
" , Temp_SubMsrs.Complexity" & _
" , Temp_SubMsrs.Denom_Only" & _
"FROM Temp_SubMsrs" & _
"WHERE Temp_SubMsrs.Parent = " & Me.Msr_Key.Value & _
"ORDER BY Temp_SubMsrs.Submeasure Name;"
End If
'User RowSrc_Str to update the Submeasures field appropriately
Me.Submsrs.RowSource = RowSrc_Str
Me.Submsrs.Requery
End Sub
Private Sub New_Sub_Click()
'
'Ensure we have a Key for this measure already
If Me.Msr_Key.Value = "" Then
'notify
MsgBox "New submeasures cannot be created until a Key has been provided for the parent measure.", vbOKOnly, "Unable to Create Submeasures"
Else
'Open the form
DoCmd.OpenForm "New_SubMsr_Form"
'Set the form mode & Parent_Key values
Forms![New_SubMsr_Form]![Form_Mode].Value = "New"
Forms![New_SubMsr_Form]![Parent_Key].Value = Me.Msr_Key.Value
'Hide the Msr Form
Me.Visible = False
End If
End Sub
And the full VBA from the New_SubMsr_Form is here:
Option Compare Database
Private Sub Cancel_Btn_Click()
'
'Clear the form
Me.SubMsr_Name.Value = Me.SubMsr_Name.DefaultValue
Me.SubMsr_Key.Value = Me.SubMsr_Key.DefaultValue
Me.Complexity.Value = Me.Complexity.DefaultValue
Me.Denom_Only.Value = Me.Denom_Only.DefaultValue
'Hide the form
Me.Visible = False
'Unhide the Msr Form (if there is one)
If Not (Me.Parent_Key.Value = "" Or IsNull(Me.Parent_Key.Value)) Then
'Make the form visible
'Forms![New_Msr_Form].Visible
End If 'else there is no form to make visible
End Sub
Private Sub Denom_Only_Click()
'
'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Denom_Only)
End Sub
Private Sub Form_Load()
'
'Make sure the fields start on the correct values
If Me.Form_Mode.Value = "" Or IsNull(Me.Form_Mode.Value) Then
'First creation, use default values
Me.SubMsr_Name.Value = Me.SubMsr_Name.DefaultValue
Me.SubMsr_Key.Value = Me.SubMsr_Key.DefaultValue
Me.Complexity.Value = Me.Complexity.DefaultValue
Me.Denom_Only.Value = Me.Denom_Only.DefaultValue
ElseIf Me.Form_Mode.Value = "New" Then
'Default values
Me.SubMsr_Name.Value = Me.SubMsr_Name.DefaultValue
Me.SubMsr_Key.Value = Me.SubMsr_Key.DefaultValue
Me.Complexity.Value = Me.Complexity.DefaultValue
Me.Denom_Only.Value = Me.Denom_Only.DefaultValue
Else
'Update, get correct values
'Me.SubMsr_Name.Value = access.
'Me.SubMsr_Key.Value = Me.SubMsr_Key.DefaultValue
'Me.Complexity.Value = Me.Complexity.DefaultValue
'Me.Denom_Only.Value =
End If
'Set focus on name
Me.SubMsr_Name.SetFocus
End Sub
Private Sub Save_Btn_Click()
'
Dim Valid_Sub As Boolean
Valid_Sub = False
'Validate that the submeasure is unique
If Valid_Sub Then
'Create the Temp_SubMsrs record
DoCmd.OpenQuery Temp_SubMsr_Create
'Short cut to clearing & exiting SubMsr form is to now invoke Cancel_Click
'Me.Cancel_Btn.Click
Else
'Notify user
MsgBox "temp prompt text", vbOKOnly
End If
End Sub
Check_Uncheck is a function that basically turns a TextBox into a scalable CheckBox (since the native ones are entirely too small). It's code for context:
Public Sub Check_Uncheck(ByRef TBox As TextBox)
'
'Determine current value
If TBox.Value = "X" Then
TBox.Value = " "
Else
TBox.Value = "X"
End If
'Deselect
TBox.SelLength = 0
End Sub

Why does this VB6 ActiveX Class Terminates Instantly?

Given the following ( extremely simple ) example :
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Foo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Sub Class_Initialize()
MsgBox "Initialized!"
End Sub
Private Sub Class_Terminate()
MsgBox "Terminated! ( FFFUUUUUUUUU )"
End Sub
When I declare this class within another class and attempt to instantiate it :
'Bar Class
Dim FooClassObject As Foo
Private Sub Class_Initialize( )
FooClassObject = New Foo
End Sub
Foo is instantiated, but then immediately terminates.
Why?

vbscript check if email is sent

I have created a script to send a weekly report but I don't know how to implement the status message if the email is successfully sent. Currently I just have a message which shows up on confirm to send the message, but that does not really check if the email is sent.
This is my script:
Dim fso, path, file, recentDate, recentFile, ToAddress, FromAddress, MessageSubject, MyTime, MessageBody, MessageAttachment, ol, ns, newMail
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("C:\REPORTData\temp").Files
If (recentFile is Nothing) Then
If UCase(fso.GetExtensionName(file.name)) <> "PDF" Then
Set recentFile = file
End If
ElseIf (file.DateLastModified > recentFile.DateLastModified) Then
If UCase(fso.GetExtensionName(file.name)) <> "PDF" Then
Set recentFile = file
End If
End If
Next
ToAddress = "randomemail#randomemail.com"
MessageSubject = "Emailing: "+recentFile.Name
MessageBody = "Your message is ready to be sent with the following file or link attachments: "+recentFile.Name
MessageAttachment = "C:\REPORTData\temp\"+recentFile.Name
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
CurrentWeek = Right(recentFile.Name, 2)
result = MsgBox ("Send REPORT for week: "+CurrentWeek, vbYesNo + vbQuestion, "REPORT Sender v.0.1")
Select Case result
Case vbYes
newMail.Send
Set shell = CreateObject("Wscript.Shell")
shell.Popup "Your REPORT for week "+CurrentWeek+" has been sent", 2, "SUCCESS"
Case vbNo
End Select
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "dcandy#gmail.com"
emailObj.To = "dcandy#gmail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
emailObj.AddAttachment "c:\windows\win.ini"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then
Msgbox "Done"
Else
Msgbox err.number
End if
is how.

Form Load/Unload Event Not Triggered After Importing Form in Access 2007

So I just manually split a database following the steps found Here. For some reason the load event is not triggered on one form and on another the unload event is not triggered (but in each case, the opposite one does work). The second form (Unload not working) also refuses to go into design mode until I close it manually and then open it into design mode. I have confirmed that the open and close events are linked properly to their corresponding VBA code so I know that isn't it.
Any help with resolving this issue would be appreciated.
Edit-
Here is the code for the Load:
Private Sub Form_Load()
Dim scr As ScriptControl
Dim SQL As String
CheckConnection
Set scr = New ScriptControl
SQL = "UPDATE [Part Number] SET [Part Number].[Select] = False WHERE ((([Part Number].[Select])=True));"
CurrentDb.Execute SQL
scr.Language = "VBScript"
scr.AddCode "Sub T :Dim ChangeReg: Set ChangeReg = CreateObject(""WScript.Shell""):ChangeReg.regwrite " & _
"""HKCU\Software\Microsoft\Office\12.0\Access\Security\VBAWarnings"", ""1"", ""REG_DWORD"" : " & _
"Set ChangeReg = CreateObject(""WScript.Shell""):ChangeReg.regwrite " & _
"""HKCU\Software\Microsoft\Office\12.0\Excel\Security\VBAWarnings"", ""1"", ""REG_DWORD"": end sub"
scr.Run "T"
Locked = False
CancelBupdate = False
LockOff
USRID = Environ("Username")
TTTCount = 0
Started = True
SourceSelect.Value = 1
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
DoCmd.ShowToolbar "Ribbon", acToolbarNo
ChgFrmOpen = False
Me.LocationSelect.Visible = False
Me.ClrSupLoc.Visible = False
Me.Label20.Visible = False
PSOn = True
Me.RepSelect.Value = ""
Me.SupplierSelect.Value = ""
Me.SupNumSelect.Value = ""
Me.LocationSelect.Value = ""
Me.Base5Select.Value = ""
Me.FullNbrSelect.Value = ""
Me.Label104.Caption = "Last Updated On: " & DLookup("[Last Updated]", "[Last Updated]")
ChangeCount = 0
CT = ""
CPP = ""
PGNP = ""
UpdateSub '****
InfoGet
RunFilter
Cascade
Me.Requery
Select Case USRID
Case "vn034153"
UsrInfoSt = "Logged in as User"
Case "vn043156"
UsrInfoSt = "Logged in as User"
Blah
Case "vn034157"
UsrInfoSt = "Logged in as Admin"
Me.UpdateButton.Visible = True
Case "vn034160"
UsrInfoSt = "Logged in as User"
Case "vn028040"
UsrInfoSt = "Logged in as User"
Case "vn028033"
UsrInfoSt = "Logged in as Admin"
Me.UpdateButton.Visible = True
Case "vn034931"
UsrInfoSt = "Logged in as User"
Case Else
UsrInfoSt = "Logged in as User"
End Select
Me.UsrInfo.Caption = UsrInfoSt
Application.SetOption "Confirm Action Queries", 0
Application.SetOption "Confirm Document Deletions", 0
Application.SetOption "Confirm Record Changes", 0
DoCmd.SetWarnings False
Application.SetOption "Auto compact", True
End Sub
And here is the code for the unload (using a cmd button and neither sub runs):
Private Sub OpenDatabase_Click()
DoCmd.OpenForm "2BHPartsDatabaseX"
DoCmd.Close acForm, Me.Name
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim TDF As TableDef
Dim QDF As QueryDef
Dim DBS As Database
Set DBS = CurrentDb()
Me.ReportForm.SourceObject = ""
For Each QDF In DBS.QueryDefs
If QDF.Name = "TempQRYX" Or QDF.Name = "DistinctPGNQry" Then
DBS.QueryDefs.Delete QDF.Name
End If
Next
For Each TDF In DBS.TableDefs
If TDF.Name = "ProjectTable" Then
DBS.TableDefs.Delete TDF.Name
Exit For
End If
Next
Application.SetOption "Confirm Action Queries", 1
Application.SetOption "Confirm Document Deletions", 1
Application.SetOption "Confirm Record Changes", 1
DoCmd.SetWarnings True
End Sub
I would comment (rem) out all the code in the Form_Load Event, and put a breakpoint on the
Sub procedure, then open the form to see if the event fires. After I see it fire,
I would begin to "un-rem" each line until the code line affecting the load event
is found.
I would do the same with the "Unload" issue.

Sending email with multiple attachments vb6

Can someone help me.How to send an email with multiples attachments.
I am using cdo and SMTP Send Mail for VB6. Everything works great except I am only able to send one attachment at a time.
here's the code
Public Function SendMail(sTo As String, sSubject As String, sFrom As String, _
sBody As String, sSmtpServer As String, iSmtpPort As Integer, _
sSmtpUser As String, sSmtpPword As String, _
sFilePath As String, bSmtpSSL As Boolean) As String
On Error GoTo SendMail_Error:
Dim lobj_cdomsg As CDO.Message
Set lobj_cdomsg = New CDO.Message
lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = sSmtpServer
lobj_cdomsg.Configuration.Fields(cdoSMTPServerPort) = iSmtpPort
lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
lobj_cdomsg.Configuration.Fields(cdoSMTPAuthenticate) = cdoBasic
lobj_cdomsg.Configuration.Fields(cdoSendUserName) = sSmtpUser
lobj_cdomsg.Configuration.Fields(cdoSendPassword) = sSmtpPword
lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = cdoSendUsingPort
lobj_cdomsg.Configuration.Fields.Update
lobj_cdomsg.To = sTo
lobj_cdomsg.From = sFrom
lobj_cdomsg.Subject = sSubject
lobj_cdomsg.TextBody = sBody
If Trim$(sFilePath) <> vbNullString Then
lobj_cdomsg.AddAttachment (sFilePath)
End If
lobj_cdomsg.Send
Set lobj_cdomsg = Nothing
SendMail = "ok"
Exit Function
SendMail_Error:
SendMail = Err.Description
End Function
Private Sub cmdSend_Click()
Dim retVal As String
Dim objControl As Control
For Each objControl In Me.Controls
If TypeOf objControl Is TextBox Then
If Trim$(objControl.Text) = vbNullString And LCase$(objControl.Name) <> "txtAttach" Then
Label2.Caption = "Error: All fields are required!"
Exit Sub
End If
End If
Next
Frame1.Enabled = False
Frame2.Enabled = False
cmdSend.Enabled = False
Label2.Caption = "Sending..."
retVal = SendMail(Trim$(txtTo.Text), _
Trim$(txtSubject.Text), _
Trim$(txtFromName.Text) & "<" & Trim$(txtFromEmail.Text) & ">", _
Trim$(txtMsg.Text), _
Trim$(txtServer.Text), _
CInt(Trim$(txtPort.Text)), _
Trim$(txtUsername.Text), _
Trim$(txtPassword.Text), _
Trim$(txtAttach.Text), _
CBool(chkSSL.Value))
Frame1.Enabled = True
Frame2.Enabled = True
cmdSend.Enabled = True
Label2.Caption = IIf(retVal = "ok", "Message sent!", retVal)
End Sub
Private Sub cmdBrowse_Click()
Dim sFilenames() As String
Dim i As Integer
On Local Error GoTo Err_Cancel
With cmDialog
.FileName = ""
.CancelError = True
.Filter = "All Files (*.*)|*.*|HTML Files (*.htm;*.html;*.shtml)|*.htm;*.html;*.shtml|Images (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif"
.FilterIndex = 1
.DialogTitle = "Select File Attachment(s)"
.MaxFileSize = &H7FFF
.Flags = &H4 Or &H800 Or &H40000 Or &H200 Or &H80000
.ShowOpen
' get the selected name(s)
sFilenames = Split(.FileName, vbNullChar)
End With
If UBound(sFilenames) = 0 Then
If txtAttach.Text = "" Then
txtAttach.Text = sFilenames(0)
Else
txtAttach.Text = txtAttach.Text & ";" & sFilenames(0)
End If
ElseIf UBound(sFilenames) > 0 Then
If Right$(sFilenames(0), 1) <> "\" Then sFilenames(0) = sFilenames(0) & "\"
For i = 1 To UBound(sFilenames)
If txtAttach.Text = "" Then
txtAttach.Text = sFilenames(0) & sFilenames(i)
Else
txtAttach.Text = txtAttach.Text & ";" & sFilenames(0) & sFilenames(i)
End If
Next
Else
Exit Sub
End If
Err_Cancel:
End Sub
You are only passing in one file. Try passing in an array of files and loop through the array. Or, since it looks like its semicolon delimiting the list of files selected, try to just split the list...
For Each s As String in sFilePath.Split(";"c)
lobj_cdomsg.AddAttachemt(s)
Next
I have no idea how to run a vb 6 app anymore, but if this helps, please mark it so.