Darren D
darren at activebilling.com.au
Mon Oct 15 00:06:29 CDT 2007
Hi Gustav - Perfect - As I have said many times - legend I did modify it a bit - I am assuming there already is a connection So Now I have 2 functions - 1 to get the Current DB name and the other to get the server name - See below Many thanks Darren ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function f_GetServerName() As String On Error GoTo Err_ Dim strConnect As String Dim strKey As String Dim strSearch As String Dim strServer As String strConnect = Application.CurrentProject.Connection strKey = "SOURCE=" strSearch = Mid(strConnect, InStr(1, strConnect, strKey, vbTextCompare) + Len(strKey)) strServer = Mid(strSearch, 1, InStr(1, strSearch, ";") - 1) f_ GetServerName = strServer Exit_: Exit Function Err_: DoCmd.Hourglass False MsgBox Err.Number & " " & Err.Description, vbCritical, "Error in f_ GetServerName Routine" Resume Exit_ End Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function f_dBName() As String On Error GoTo Err_ Dim rs As Object Dim con As Object Dim selSQL As String Set rs = CreateObject("ADODB.Recordset") Set con = Application.CurrentProject.Connection selSQL = "SELECT DB_NAME() AS CurrentDB" rs.Open selSQL, con, 1, 3 f_dBName = rs!CurrentDb rs.Close Set rs = Nothing Exit_: Exit Function Err_: DoCmd.Hourglass False MsgBox Err.Number & " " & Err.Description, vbCritical, "Error in f_dBName Routine" Resume Exit_ End Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, 12 October 2007 8:28 PM To: accessd at databaseadvisors.com Subject: Re: [AccessD] ADProject: Getting Database Name Hi Darren Would it be something like this: strConnect = "DATABASE=something;SERVER=192.168.1.100;PASSWORD=;PORT=3306;OPTION=3;STMT=;" strKey = "SERVER=" strSearch = Mid(strConnect, InStr(1, strConnect, strKey, vbTextCompare) + Len(strKey)) strServer = Mid(strSearch, 1, InStr(1, strSearch, ";") - 1) /gustav >>> darren at activebilling.com.au 12-10-2007 08:06 >>> Hi All Cross posted to AccessD and dba_SQL Server I want to get the Server name (Data Source) from code - I can get the dB name Now I want just the server name as well - Not all the other stuff that comes with the .Connection property Can anyone assist? Many thanks in advance Darren -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com