# Visual Basic coding Question?



## Focus2 (Nov 30, 2011)

Im doing alittle coding in visual basic, in I have two textboxes. 

Textbox1.text will have the data already appear. But textbox2 will be empty. I can I set a code that the data thats will be inserted into Textbox2.text, must match whats in textbox1.text... In if it not the correct data in the text box, in error message will appear to indicate wrong info. Thanks in advance.

:Thinkingo


----------



## AlbertMC2 (Jul 15, 2010)

Hi

Let's say you have a form with:
Text box 1 = Textbox1
Text box 2 = Textbox2
Button = Button1

Then on the Button's Click Event you can have:

```
If (TextBox1.Text <> TextBox2.Text) Then
   'Show message if values do not match
   MsgBox("Values do not match", MsgBoxStyle.OkOnly)
Else
   'do what ever you want if values match
   MsgBox("Values match", MsgBoxStyle.OkOnly)
End If
```


----------



## Focus2 (Nov 30, 2011)

*Visual Basic*

Hello,

Im making in program that will have two textboxes. Textbox1.text. will automatic have data in it. But I will have to insert the matching data in Textbox2.text that is shown in Textbox1.text. What Im try to do is, when Textbox2.text doesnt match the data in textbox1.text. The form will change to the color red. CAN SOMEONE PLEASE HELP?

:4-dontkno


----------



## Focus2 (Nov 30, 2011)

Thank you, that did the job.


----------



## Ninjaboi (Dec 27, 2010)

**Merged new thread with this previously created thread to prevent duplication**

I needed to merge your two threads Gregory, due to the newer one asking a question that is in direct relation to the same question you asked here.

In the if-statement that Albert provided, all you would have to add to it in order to achieve the form color change when the values aren't the same is add a line like this in it:


```
If (TextBox1.Text <> TextBox2.Text) Then
   'Show message if values do not match
[SIZE=2][FONT=Verdana]  [B]TestForm.BackColor = &H000000FF&[/B][/FONT][/SIZE]
   MsgBox("Values do not match", MsgBoxStyle.OkOnly)
Else
   'do what ever you want if values match
   MsgBox("Values match", MsgBoxStyle.OkOnly)
End If
```
A quick tutorial on form and control manipulation can be found here:

Visual Basic Tutorial Lesson 3:Working With Controls


----------



## Focus2 (Nov 30, 2011)

Im having problems with insert data into MS Access. I have an table with is name Beginning of Line Data, in im trying to insert codes into the table from visual basic program. How can I send data so it can show in the row I desirer.. I might need a select statement as well. But Im really having problems with this.. Nelow is my code. Thanks.


Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim cmd As OleDb.OleDbDataReader
Try
Dim AccessCommand As New OleDb.OleDbCommand
Dim AccessConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\Documents and Settings\Captain\My Documents\YF Lines.mdb;")
AccessCommand.CommandText = "Insert Into Beginning of Line Data (SEQ #, VIN #)" & " values(" & TextBox1.Text & "','" & TextBox2.Text & "')"
AccessCommand.Connection = AccessConnection
AccessConnection.Open()
While cmd.Read

TextBox2.Text = cmd.Item(3)
TextBox1.Text = cmd.Item(2)
End While
AccessConnection.Close()
Catch ex As Exception
End Try
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End Class


----------



## Focus2 (Nov 30, 2011)

How do i go by doing a select statement from vb into MS Access, I now have the instatement working. But I will need it to seclect the a specified data in a table, in insert data in the empty row. Again, it insert fine, just need to kno how to select the entire row, the I can insert data into the empty row... Thanks in advance...

Option Explicit On
Public Class Form1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Try
If TextBox1.Text = "" Then
TextBox1.Text = ""
End If
Catch ex As Exception
End Try
TextBox3.Text = "" '(Erase textbox after input')
TextBox4.Text = ""
TextBox9.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox2.Text = ""
Dim AccessDR As OleDb.OleDbDataReader
Try
Dim AccessCommand As New OleDb.OleDbCommand
Dim AccessConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\Documents and Settings\Captain\My Documents\YF Lines.mdb;")
AccessCommand.CommandText = "SELECT * FROM [Beginning of Line Data] WHERE [Part Description] = '" & TextBox1.Text & "' "
AccessCommand.Connection = AccessConnection
AccessConnection.Open()
AccessDR = AccessCommand.ExecuteReader
While AccessDR.Read
'TextBox3.Text = AccessDR.Item(3)
'TextBox2.Text = AccessDR.Item(2)
'TextBox9.Text = AccessDR.Item(4)
'TextBox6.Text = AccessDR.Item(1)
TextBox3.Text = AccessDR.Item(4)
TextBox2.Text = AccessDR.Item(3)
TextBox9.Text = AccessDR.Item(4)
TextBox6.Text = AccessDR.Item(2)
End While
If TextBox9.Text <> "PIC" Then
TextBox9.Visible = False
Else
TextBox9.Visible = True
End If
AccessConnection.Close()
Catch ex As Exception
End Try
Exit Sub
TextBox4.Focus()
End Sub
Private Sub Form3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyDown
End Sub
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As OleDb.OleDbDataReader
Try
Dim AccessCommand As New OleDb.OleDbCommand
Dim AccessConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\Documents and Settings\Captain\My Documents\YF Lines.mdb;")
AccessCommand.CommandText = "Insert Into [Beginning of Line Data] ([SEQ #], [VIN #]) values('" & TextBox4.Text & "','" & TextBox5.Text & "')"
MessageBox.Show(AccessCommand.CommandText)
AccessCommand.Connection = AccessConnection
AccessConnection.Open()
cmd = AccessCommand.ExecuteReader
While cmd.Read

TextBox4.Text = cmd.Item(6)
TextBox5.Text = cmd.Item(7)
End While
AccessConnection.Close()
Catch ex As Exception
End Try
End Sub
Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class


----------



## Ninjaboi (Dec 27, 2010)

This code should help you select the entire row:


```
If MyDataGridView.RowCount > 0 Then
    MyDataGridView.ClearSelection()
    MyDataGridView.CurrentCell = Me.Rows(0).Cells(0)
    MyDataGridView.Rows(0).Selected = True
End If
```
The *"DataGridView Selection Mode"* property must be *"FullRowSelect"*.

Source(s):

selecting full row of datagridview in vb.net on form_Load - Stack Overflow
Select Entire Row With A Named Variable


----------



## Ninjaboi (Dec 27, 2010)

*Re: MS Access Help....*

Hello Focus2, welcome to TSF!

Is this a homework assignment or school project by chance?


----------



## Focus2 (Nov 30, 2011)

*Re: MS Access Help....*

No, this is a program Im working on at work. In having problems with it.


----------



## Ninjaboi (Dec 27, 2010)

Okay, I was just making sure due to the same code being in more than one thread ( don't worry, another staff member informed me of your account situation ).

Are you still having trouble selecting the entire row in your Access database? Or is this another problem that you've now encountered?


----------



## Focus2 (Nov 30, 2011)

I finally figure it out. Thanks for the help tho..


----------



## Ninjaboi (Dec 27, 2010)

No problem, if you think this thread is solved, mark it so. If you still need help with it, keep it as unsolved and simply create a new post with the new information you have about your situation.

Happy coding!


----------



## Focus2 (Nov 30, 2011)

Need help with textbox in visual basic..

Im making in program. In in this program i have textbox.text, which I wont to have a be able to make in messgaebox pop up if the text inside of the textbox is change by the user. Can someone plese help.. Thanks


----------



## AlbertMC2 (Jul 15, 2010)

Hi

You cannot use the TextChanged event to do this as every letter/character you enter in the textbox will display a message box.

So what you can do is save the text in the text box to a variable when the text box gets the focus.
Then when you leave (lose focus event) or enter in (Enter event) the text box it compares the text in the text box to the variable. If they differ a message pops up else you carry on.


```
Public Class Form1

    Private test As String

    Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
        test = TextBox1.Text 'save text to variable
    End Sub

    Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
        If TextBox1.Text <> test Then 'compare variable to current text
            MsgBox(TextBox1.Text, MsgBoxStyle.OkOnly, "Text Changed") 'if different then show message
        End If
    End Sub

End Class
```


----------



## Focus2 (Nov 30, 2011)

Thanks, that worked fine. :beerchug:


----------



## Focus2 (Nov 30, 2011)

Im making in program that pull data from MS Acess, in if there are only ten rows left in the table for the program can pull up. It the program willl send out an alert. Imade the code to send out emails. But having problems, with visual basic determine how many rows are in table. To send a alert email, to indicate there are 10 more rows left in access table.

Thanks


----------



## Focus2 (Nov 30, 2011)

Im using visual basic,. an MS Access program. In I'm trying to make in program that will select all row that I chose from a textboxes.

eXAMPLE.. Let say I wont to select record 1-20 on the Access Table, in it show up on a list box in visual basic..


----------



## AlbertMC2 (Jul 15, 2010)

What do you mean by 10 rows left in the table? In Access, as far as I know, there isn't a limit on the number of records a table can have, but there is a limit on the size of a database.
See this page on Access 2007/2010 Database limits: Access 2010 specifications - Access - Office.com


----------



## Focus2 (Nov 30, 2011)

I have an table, which have column header name SEQ, an Part Description. The SEQ Column is set as Auto Number, in the Part Decription is set as text. 
The Seq number keep increasing, but Let say I wont only row 1-10 . How do I go by selecting rows 1-10 Part Descriptions?

I started on the query below, but is stcuk at the moment.


SELECT * [Part Description] FROM [YF End of Line Data] WHERE [SEQ]=1


----------



## AlbertMC2 (Jul 15, 2010)

Are you actually doing this in Microsoft Access? As in using VBA?

Or

Are you doing this in Visual Basic which is connecting to a data source (the MS Access database) ie are you only using Access to hold the tables and doing all the programming/forms etc in Visual Basic?


----------



## Focus2 (Nov 30, 2011)

Im am doing the programming from Visual Basic, in pulling data from the Access Table.

In Yes im using Access to hold the tables and doing all the programming in Visual Basic


----------



## Focus2 (Nov 30, 2011)

This might be confusing but, it a learning process. I have this vb program, in it pulls data from a MS Access table. When I select the data i wont from a textbox in vb, how to I go by printing it to a Label. Using a ZPL Code. Basically what I'm trying to do is, lets say I put in the text box I wont row 1-20 in the table. In it does select the data, but how do I print the data from the table into a Label.

The code is below, if someone familar with this. Please Help Me Out..
Thanks an Advance,

Option Explicit On
Imports YF_Bulk_Load_Label_Program.ZebraLabels
Public Class Form1
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim _print As New ZebraPrint ' This whole process start off the printing process'
_print.StartWrite("//10.53.252.196//YFTEST") 'Inorder to print from the printer, must input the following code'
_print.Write("^XA")
_print.Write("^SZ2^JMA")
_print.Write("^MCY^PMN")
_print.Write("^PW802~JSN")
_print.Write("^JZY")
_print.Write("^LH0,0^LRN")
_print.Write("^XZ")
_print.Write("^XA")
_print.Write("^FT240,50")
_print.Write("^CI0")
'_print.Write("^A0N,12,14^FDHMMA Rack ID:^FS")
_print.Write("^FT230,15") ''''FOR HMMA RACK IS.. SECOND NUM MOVES UP OR DOWN.... 
_print.Write("^A0N,14,16^FDHMMA Rack ID:^FS")
_print.Write("^FT230,75") '''''line feed
_print.Write("^A0N,14,16^FDLine Feed:^FS")
_print.Write("^FT230,95") 'THE pART # ON THE TOP 2ND NUMBER MOVE LEFT OR RIGHT
_print.Write("^A0N,24,22^FD" & ComboBox1.Text & "^FS") 'THE pART # ON THE TOP XIZE
_print.Write("^FT16,75")
_print.Write("^FT206,262") ' THIS for PHA BODY SYSTEM LOAD ID:
_print.Write("^FT16,20") ''Rack'
_print.Write("^A0N,17,19^FDPHA Body Systems^FS")
_print.Write("^FT16,100") ''Rack
_print.Write("^A0N,15,17^FDRack:^FS")
_print.Write("^FT562,1186")
_print.Write("^FS^FO225,0")
_print.Write("^GB0,117,2^FS") '' straight line, that increase or decrease line.
_print.Write("^FO0,115") ' LINE THAT MOVE BY LINE FEED.. NUMBER 2 MOVES UP OR DOWN...
_print.Write("^GB780,0,2^FS")
_print.Write("^FO230,60") ' tHIS THE LINE BELOW HMMA RACK ID:
_print.Write("^GB550,0,2^FS")
_print.Write("^FO0,530") ' LINE FOR THE BOTTOM, RIGHT ABOVE # 20
_print.Write("^GB780,0,2^FS") ' LINE FOR THE BOTTOM
_print.Write("^FS^FT16,140")
_print.Write("^A0N,15,17^FD1.^FS")
_print.Write("^FT16,160")
_print.Write("^A0N,15,17^FD2.^FS")
_print.Write("^FT16,180")
_print.Write("^A0N,15,17^FD3.^FS")
_print.Write("^FT16,200")
_print.Write("^A0N,15,17^FD4.^FS")
_print.Write("^FT16,220")
_print.Write("^A0N,15,17^FD5.^FS")
_print.Write("^FT16,240")
_print.Write("^A0N,15,17^FD6.^FS")
_print.Write("^FT16,260")
_print.Write("^A0N,15,17^FD7.^FS")
_print.Write("^FT16,280")
_print.Write("^A0N,15,17^FD8.^FS")
_print.Write("^FT16,300")
_print.Write("^A0N,15,17^FD9.^FS")
_print.Write("^FT16,320") ''
_print.Write("^A0N,15,17^FD10.^FS") '''''''
_print.Write("^FT16,340")
_print.Write("^A0N,15,17^FD11.^FS")
_print.Write("^FT16,360")
_print.Write("^A0N,15,17^FD12.^FS")
_print.Write("^FT16,380")
_print.Write("^A0N,15,17^FD13.^FS")
_print.Write("^FT16,400")
_print.Write("^A0N,15,17^FD14.^FS")
_print.Write("^FT16,420")
_print.Write("^A0N,15,17^FD15.^FS")
_print.Write("^FT16,440")
_print.Write("^A0N,15,17^FD16.^FS")
_print.Write("^FT16,460")
_print.Write("^A0N,15,17^FD17.^FS")
_print.Write("^FT16,480")
_print.Write("^A0N,15,17^FD18.^FS")
_print.Write("^FT16,500")
_print.Write("^A0N,15,17^FD19.^FS")
_print.Write("^FT16,520")
_print.Write("^A0N,15,17^FD20.^FS")
_print.Write(" ^FT12,540")
'_print.Write("^A0N,15,17^FD" & Date.Now & "^FS")
'_print.Write(" ^FT12,580")
_print.Write("^XZ")
_print.EndWrite()
Dim AccessDR As OleDb.OleDbDataReader
Try
Dim AccessCommand As New OleDb.OleDbCommand
Dim AccessConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\Documents and Settings\Captain\My Documents\YF Lines.mdb;")
AccessCommand.CommandText = "SELECT [Part Description] FROM [YF End of Line Data] WHERE [SEQ]>=" & TextBox1.Text & " and [SEQ]<=" & TextBox2.Text & " "
'"SELECT [Part Description] FROM [YF End of Line Data] WHERE [SEQ]>=" & TextBox1.Text & " and [SEQ]<=" & TextBox2.Text & " "
'"SELECT * FROM [YF End of Line Data] WHERE [SEQ]= " & TextBox1.Text & " "
AccessCommand.Connection = AccessConnection
AccessConnection.Open()
AccessDR = AccessCommand.ExecuteReader
While AccessDR.Read
ListBox1.Items.Add(AccessDR.Item(0))
End While
AccessConnection.Close()
Catch ex As Exception
End Try
Exit Sub
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
End Class


----------



## Focus2 (Nov 30, 2011)

*Need Help With Ms Access-VB Coding*

Im pullin data from a Access Table, but I also wont it to print all the data which in the table to Print into a Label. Im using VB to select the data, but when it selected the data I wont, how do I print it form a ZPL code.. The ZPL Code is below:

Thanks,


Dim AccessDR As OleDb.OleDbDataReader
 
Try
Dim AccessCommand As New OleDb.OleDbCommand
Dim AccessConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\Documents and Settings\Captain\My Documents\YF Lines.mdb;")
AccessCommand.CommandText = "SELECT [Part Description] FROM [YF End of Line Data] WHERE [SEQ]>=" & TextBox1.Text & " and [SEQ]<=" & TextBox2.Text & " "
AccessCommand.Connection = AccessConnection
AccessConnection.Open()
AccessDR = AccessCommand.ExecuteReader
While AccessDR.Read
ListBox1.Items.Add(AccessDR.Item(0))
End While
AccessConnection.Close()
Catch ex As Exception
End Try

Dim _print As New ZebraPrint ' This whole process start off the printing process'
_print.StartWrite("//10.53.252.35//YFTEST") 'Inorder to print from the printer, must input the following code'
_print.Write("^XA")
_print.Write("^SZ2^JMA")
_print.Write("^MCY^PMN")
_print.Write("^PW802~JSN")
_print.Write("^JZY")
_print.Write("^LH0,0^LRN")
_print.Write("^XZ")
_print.Write("^XA")
_print.Write("^FT240,50")
_print.Write("^CI0")
'_print.Write("^A0N,12,14^FDHMMA Rack ID:^FS")
_print.Write("^FT230,15") ''''FOR HMMA RACK IS.. SECOND NUM MOVES UP OR DOWN.... 
_print.Write("^A0N,14,16^FDHMMA Rack ID:^FS")
_print.Write("^FT230,75") '''''line feed
_print.Write("^A0N,14,16^FDLine Feed:^FS")
_print.Write("^FT230,95") 'THE pART # ON THE TOP 2ND NUMBER MOVE LEFT OR RIGHT
_print.Write("^A0N,24,22^FD" & ComboBox1.Text & "^FS") 'THE pART # ON THE TOP XIZE
_print.Write("^FT16,75")
_print.Write("^FT206,262") ' THIS for PHA BODY SYSTEM LOAD ID:
_print.Write("^FT16,20") ''Rack'
_print.Write("^A0N,17,19^FDPHA Body Systems^FS")
_print.Write("^FT16,100") ''Rack
_print.Write("^A0N,15,17^FDRack:^FS")
_print.Write("^FT562,1186")
_print.Write("^FS^FO225,0")
_print.Write("^GB0,117,2^FS") '' straight line, that increase or decrease line.
_print.Write("^FO0,115") ' LINE THAT MOVE BY LINE FEED.. NUMBER 2 MOVES UP OR DOWN...
_print.Write("^GB780,0,2^FS")
_print.Write("^FO230,60") ' tHIS THE LINE BELOW HMMA RACK ID:
_print.Write("^GB550,0,2^FS")
_print.Write("^FO0,530") ' LINE FOR THE BOTTOM, RIGHT ABOVE # 20
_print.Write("^GB780,0,2^FS") ' LINE FOR THE BOTTOM
_print.Write("^FS^FT16,140")
_print.Write("^A0N,15,17^FD1.^FS")
_print.Write("^FT16,160")
_print.Write("^A0N,15,17^FD2.^FS")
_print.Write("^FT16,180")
_print.Write("^A0N,15,17^FD3.^FS")
_print.Write("^FT16,200")
_print.Write("^A0N,15,17^FD4.^FS")
_print.Write("^FT16,220")
_print.Write("^A0N,15,17^FD5.^FS")
_print.Write("^FT16,240")
_print.Write("^A0N,15,17^FD6.^FS")
_print.Write("^FT16,260")
_print.Write("^A0N,15,17^FD7.^FS")
_print.Write("^FT16,280")
_print.Write("^A0N,15,17^FD8.^FS")
_print.Write("^FT16,300")
_print.Write("^A0N,15,17^FD9.^FS")
_print.Write("^FT16,320") ''
_print.Write("^A0N,15,17^FD10.^FS") '''''''
_print.Write("^FT16,340")
_print.Write("^A0N,15,17^FD11.^FS")
_print.Write("^FT16,360")
_print.Write("^A0N,15,17^FD12.^FS")
_print.Write("^FT16,380")
_print.Write("^A0N,15,17^FD13.^FS")
_print.Write("^FT16,400")
_print.Write("^A0N,15,17^FD14.^FS")
_print.Write("^FT16,420")
_print.Write("^A0N,15,17^FD15.^FS")
_print.Write("^FT16,440")
_print.Write("^A0N,15,17^FD16.^FS")
_print.Write("^FT16,460")
_print.Write("^A0N,15,17^FD17.^FS")
_print.Write("^FT16,480")
_print.Write("^A0N,15,17^FD18.^FS")
_print.Write("^FT16,500")
_print.Write("^A0N,15,17^FD19.^FS")
_print.Write("^FT16,520")
_print.Write("^A0N,15,17^FD20.^FS")
_print.Write(" ^FT12,540")
'_print.Write("^A0N,15,17^FD" & Date.Now & "^FS")
'_print.Write(" ^FT12,580")
_print.Write("^XZ")
_print.EndWrite()
Exit Sub
End Sub
:wavey:


----------



## Focus2 (Nov 30, 2011)

Do anyone know how to get in file out a folder, when it a excel file.. I tried the code below, but it seems to not work as I need. It keep saying the file name doesnt exist. Maybe I have the wrong function in the code. 

Thanks,

.AddAttachment("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\,*.xls")


----------



## Focus2 (Nov 30, 2011)

:4-dontknoDo anyone know how to get in file out a folder, when it a excel file.. I tried the code below, but it seems to not work as I need. It keep saying the file name doesnt exist. Maybe I have the wrong function in the code. But what Im trying to do is, make in code that send out emails, but also get whatever file in that folder. In send it to the person I eont too.

Thanks,

.AddAttachment(\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\,*.xls)





Dim dDir As New DirectoryInfo(sDir)
Dim fFileSystemInfo As FileSystemInfo
For Each fFileSystemInfo In dDir.GetFileSystemInfos()
If fFileSystemInfo.Name.ToString.StartsWith("Daily Report") Then
Try
Dim iMsg, iConf, Flds As Object
iMsg = CreateObject("CDO.Message")
iConf = CreateObject("CDO.Configuration")
Const cdobasic = 1
iConf.Load(-1)
Flds = iConf.Fields
With (Flds)
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "sniper.phaus.us"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdobasic
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "phabs_it"
.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "monty139"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update()
End With
With iMsg
.Configuration = iConf
.To = "[email protected];" ' The people the email will be sent to'
'.BCC = mailbcclist
.From = "[email protected]"
.Subject = "Daily Report" ' Name of the Email Subject'
.AddAttachment("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\,*.xls") '(Where File will be Saved in local drive)'
End With
iMsg.send()
iMsg = Nothing
MessageBox.Show(fFileSystemInfo.Name.ToString)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
Next
MessageBox.Show("The Email Has Been Sent")
'Exit Sub


----------



## AlbertMC2 (Jul 15, 2010)

Hi

You can use something like to get the full name of the file:

```
Dim lookinDir As New IO.DirectoryInfo("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\")
        Dim FileList As IO.FileInfo() = lookinDir.GetFiles("*.xls")
        Dim FilInf As IO.FileInfo
        Dim FilName As Object

        For Each FilInf In FileList
            FilName = FilInf.FullName
        Next
```
Then use the FilName variable for:

```
.AddAttachment(FilName)
```
I have not tested this so let me know if it works or not.


----------



## Focus2 (Nov 30, 2011)

It keep say The file Name, directory, or volume label are incorrect.

On the .Addattachment(FilName)
Should it be like this? 
.AddAttachment("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\")


----------



## Focus2 (Nov 30, 2011)

This what I have now... But like I mention, it give in the above statment, in gives a error message on the 
.AddAttachment(\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\).
 
 
Dim lookinDir As New IO.DirectoryInfo("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\")
Dim FileList As IO.FileInfo() = lookinDir.GetFiles("*.xls")
Dim FilInf As IO.FileInfo
Dim FilName As Object
For Each FilInf In FileList
FilName = FilInf.FullName
Next

Try
Dim iMsg, iConf, Flds As Object
iMsg = CreateObject("CDO.Message")
iConf = CreateObject("CDO.Configuration")
Const cdobasic = 1
iConf.Load(-1)
Flds = iConf.Fields
With (Flds)
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "sniper.phaus.us"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdobasic
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "phabs_it"
.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "monty139"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update()
End With
MessageBox.Show("The Email Has Been Sent")
With iMsg
.Configuration = iConf
.To = "[email protected];" ' The people the email will be sent to'
'.BCC = mailbcclist
.From = "[email protected]"
.Subject = "Daily Report" ' Name of the Email Subject'
.AddAttachment("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\")
' .AddAttachment(".xls") '(Where File will be Saved in local drive)'
End With
iMsg.send()
iMsg = Nothing
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try


----------



## AlbertMC2 (Jul 15, 2010)

No.
What happens is that this section:

```
Dim lookinDir As New IO.DirectoryInfo("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\")
        Dim FileList As IO.FileInfo() = lookinDir.GetFiles("*.xls")
        Dim FilInf As IO.FileInfo
        Dim FilName As Object

        For Each FilInf In FileList
            FilName = FilInf.FullName
        Next
```
looks in your folder (\\mtgfps001\share\Operations\......) for any *.xls files
When it finds any it will place the* full path + filename* into the variable *FilName*
Then when you want to attach a file you just use *FilName *instead of manually puting in the location/folder+File Name
So instead of

```
.AddAttachment("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\")
```
You would just use (Note the use of the variable *Filname*)

```
.AddAttachment(FilName)
```
The only problem is that if there are more than 1 xls file in the folder it will look for all the files and assign the full path + File Name to the *last *xls file it finds.
Note once again I have not tested this.


----------



## Focus2 (Nov 30, 2011)

I tried that in its giving me an error message, which is saying. System.IO.FileFoundException: The specified protocol unknown.
I put what you gave below, below like you mention.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lookinDir As New IO.DirectoryInfo("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\")
Dim FileList As IO.FileInfo() = lookinDir.GetFiles("*.xls")
Dim FilInf As IO.FileInfo
Dim FilName As Object
For Each FilInf In FileList
FilName = FilInf.FullName
Next
Try
Dim iMsg, iConf, Flds As Object
iMsg = CreateObject("CDO.Message")
iConf = CreateObject("CDO.Configuration")
Const cdobasic = 1
iConf.Load(-1)
Flds = iConf.Fields
With (Flds)
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "sniper.phaus.us"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdobasic
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "phabs_it"
.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "monty139"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update()
End With
MessageBox.Show("The Email Has Been Sent")
With iMsg
.Configuration = iConf
.To = "[email protected];" ' The people the email will be sent to'
'.BCC = mailbcclist
.From = "[email protected]"
.Subject = "Daily Report" ' Name of the Email Subject'

.AddAttachment("FilName")
'.AddAttachment("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\(*.xls*)")
'.AddAttachment("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\(*.xls*)")
End With
iMsg.send()
iMsg = Nothing
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try


----------



## Focus2 (Nov 30, 2011)

Hey ALBERTMC2, the code you gave me work fine. It pulled the attachment up, it was a problem on my half. But when I try to open the attachment on outlook, the file begins to come up, but promts the following.
The file may cannot be asscess. The file may be read only, or the server the document is stored on may not be responding. I tried to change location, on my local directory, but still getting the same error messsage. If you can help, it will be well appearicate. But if I figure out the problem, I will inform you. 

Thanks for all your help..

But thanks you you for your help.


----------



## Techial (Dec 27, 2011)

Hello Focus2.

I've read this thread a lot of times, I understand that you're using this program for email sending.

I've also looked trough you're last code, the problem is that. You CAN'T do .AddAttachment("STRING"). You'll need to remove the quotes, and leave it as .AddAttachment(FilName) Because you cannot add a string as an object.

Just like this:

```
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] Button1_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] System.[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] System.[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]) [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] Button1.Click
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] lookinDir [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] IO.[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]DirectoryInfo[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2])
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] FileList [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] IO.[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]FileInfo[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]() = lookinDir.GetFiles([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"*.xls"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2])
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] FilInf [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] IO.[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]FileInfo
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] FilName [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Object
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] FilInf [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] FileList
FilName = FilInf.FullName
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] iMsg, iConf, Flds [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Object
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]iMsg = CreateObject([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"CDO.Message"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2])
iConf = CreateObject([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"CDO.Configuration"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2])
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] cdobasic = 1
iConf.Load(-1)
Flds = iConf.Fields
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] (Flds)
.Item([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"http://schemas.microsoft.com/cdo/configuration/sendusing"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]) = 2
.Item([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"http://schemas.microsoft.com/cdo/configuration/smtpserver"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]) _
= [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"sniper.phaus.us"
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Item([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]) = cdobasic
.Item([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"http://schemas.microsoft.com/cdo/configuration/smtpserverport"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]) = 25
.Item _
([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"http://schemas.microsoft.com/cdo/configuration/sendusername"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]) = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"phabs_it"
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Item _
([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"http://schemas.microsoft.com/cdo/configuration/sendpassword"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]) = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"monty139"
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Item([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]) = 60
.Update()
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]MessageBox[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Show([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"The Email Has Been Sent"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2])
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] iMsg
.Configuration = iConf
.To = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"[email protected];"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]' The people the email will be sent to'
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]'.BCC = mailbcclist
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].From = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"[email protected]"
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Subject = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"Daily Report"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]' Name of the Email Subject'
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]
.AddAttachment([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]FilName[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2])
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]'.AddAttachment("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\(*.xls*)")
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]'.AddAttachment("\\mtgfps001\share\Operations\OperationsReview\Daily Report\Current Week\(*.xls*)")
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]iMsg.send()
iMsg = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ex [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Exception
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]MessageBox[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Show(ex.ToString)
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
```
Reply if this gives you more headache, or doesn't work.

Yours sincerely, Techial.


----------



## Focus2 (Nov 30, 2011)

It pull the excel file up, but it wont open the file up. Meaning it keep saying the following: You should always open attachment from a trustworthy source. But the same file can open up when I click on it, but when I run the program, in try to click the attachment, it give me that error message.


----------



## Techial (Dec 27, 2011)

Hello Focus2.

So you got problems with the source I sent you?
Well, firstly I want to ask...
1. If you run it as administrator?
2. Did you add the excel files to trusted files by Windows?
3. Does the program close after you open the excel file? (TEST THIS IN DEBUGGING MODE!)

I hope to get answers soon, as I love to help peoples out there 

Yours sincerely, Techial.


----------



## Focus2 (Nov 30, 2011)

Well I check all the followiing, but it seems to still giving me problems. When I click on the attachment, that was sent from my email. It shows the following; The barcode.xls' cannot be accessed. The file may be read only, or you may be trying to access a read only location. Or, the server the document is stored on may not be responding.

It keep showing that error message ever time I open the attachment from the email from the program. But the file open up fine, when I just click on in it, when its not a attachment from the program. it seems to give me this program thru the program.


----------



## Focus2 (Nov 30, 2011)

I need some Help..

I have a program that attach a xls file, from a directory. To in email, but when I open the email attachment, in it shows the file cant be open, it read only.

Do anyone kno in code that can get any file thats in a folder using the visual basic?

The code Im using is below, but like i said. The attachment comes up as needed. But it will not open at all. Is there another code that I can use to get any file out a Folder?
Dim lookinDir As New IO.DirectoryInfo("D:\Documents and Settings\Captain\New Folder")
Dim FileList As IO.FileInfo() = lookinDir.GetFiles("*.xls").


----------



## AlbertMC2 (Jul 15, 2010)

Does the attachment send? or is the email stuck in your outbox?
ie does the attachment not open from your inbox or outbox or sent items?


----------

