megatronixs
Registered User.
- Local time
- Today, 05:10
- Joined
- Aug 17, 2012
- Messages
- 719
Hi all,
I have some code that will connect to a database and the analyst name from the table. the name is stored as "Peter Cetera" and it would need to change it to "Cetera, Peter", this way I can paste it inside outlook email (happens via vba).
I use the below code to catch the name from the database:
The first value returened is the BIN nr and the second is what is interesting form me.
Hope some one will have an answer for this crazy question
Greetings.
I have some code that will connect to a database and the analyst name from the table. the name is stored as "Peter Cetera" and it would need to change it to "Cetera, Peter", this way I can paste it inside outlook email (happens via vba).
I use the below code to catch the name from the database:
Code:
Sub FindAnalystInDatabase()
'Declaring the necessary variables.
Dim con As Object
Dim rs As Object
Dim AccessFile As String
Dim strTable As String
Dim SQL As String
Dim FinalRow As Long
Dim fld As Field
AccessFile = "C:\Files\Worklist\db_Worklist.mdb"
'Set the name of the table you want to retrieve the data.
strTable = "tbl_case_list"
'Create the ADODB connection object.
Set con = CreateObject("ADODB.connection")
'Check if the object was created.
'Open the connection.
con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & AccessFile
SQL = "SELECT [BIN],[Analyst] FROM tbl_case_list Where [BIN] = 121212"
'Create the ADODB recordset object.
Set rs = CreateObject("ADODB.recordset")
'Open the recordset.
rs.Open SQL, con
'Debug.Print what is found
Do Until rs.EOF
For Each fld In rs.Fields
Debug.Print fld
Next fld
rs.MoveNext
Loop
'Close the recordet and the connection.
rs.Close
con.Close
'Release the objects.
Set rs = Nothing
Set con = Nothing
End Sub
The first value returened is the BIN nr and the second is what is interesting form me.
Hope some one will have an answer for this crazy question

Greetings.