Public Function ADDRESS(POSTCODE As String) As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String
' Create the connection string.
sConnString = "Provider=SQLOLEDB;Data Source='SQLDATABASE';" & _
"Initial Catalog=SOMEDATABASE;" & _
"User Id=sa;" & _
"Password=password"
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
' Open the connection and execute.
conn.Open sConnString
Set rs = conn.Execute("SELECT ADDRESS as Value FROM [VIEW_ADDRESS] Where [POSTCODE] =" + POSTCODE)
'------------------------------------------------------------------------------------------------------
'
'Need Some User Selection Here
'
'-------------------------------------------------------------------------------------------------------
' Check we have data.
If Not rs.EOF Then
' Transfer result.
ADDRESS = rs.Fields("Value").Value
' Close the recordset
rs.Close
Else
ADDRESS = rs.Fields("Value").Value
End If
' Clean up
If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing
End Function
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE