Ashfaque
Search Beautiful Girls from your town for night
- Local time
- Today, 22:21
- Joined
- Sep 6, 2004
- Messages
- 897
Hi,
I got this DSNless code lines somewhere from net to link SQL Server tables into my MS Access FE Db remotely. Since we dont have static /web host server, our IT keep changes IP address every now and then. Then to solve this issue I decided to place a text box on login form where remote user will type IP address first and it will save in local tbl and then below code will take that IP address and execute further.
This is successful. But it work sometime and it doesnt. Then user calls me from remote and then I have to connect his pc and then place IP address in below code line instead of using varibale MyNewIP and then it works.
Can someone tell me why this happens. I mean it connect sometime and sometime not. My remote user know the each time changed IP address because parallaly another db is running on his system and from there he know the new IP address.
So when sometimes it runs successfully no issue but when doest work even when the IP address is correct and stops at below line.
CurrentDb.TableDefs.Append td
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & MyNewIP & " ;DATABASE=mydb;UID=hr;PWD=mypwd"
I got this DSNless code lines somewhere from net to link SQL Server tables into my MS Access FE Db remotely. Since we dont have static /web host server, our IT keep changes IP address every now and then. Then to solve this issue I decided to place a text box on login form where remote user will type IP address first and it will save in local tbl and then below code will take that IP address and execute further.
This is successful. But it work sometime and it doesnt. Then user calls me from remote and then I have to connect his pc and then place IP address in below code line instead of using varibale MyNewIP and then it works.
Can someone tell me why this happens. I mean it connect sometime and sometime not. My remote user know the each time changed IP address because parallaly another db is running on his system and from there he know the new IP address.
So when sometimes it runs successfully no issue but when doest work even when the IP address is correct and stops at below line.
CurrentDb.TableDefs.Append td
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & MyNewIP & " ;DATABASE=mydb;UID=hr;PWD=mypwd"
Code:
Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String)
On Error GoTo AttachDSNLessTable_Err
Dim td As TableDef
Dim stConnect As String
For Each td In CurrentDb.TableDefs
If td.name = stLocalTableName Then
CurrentDb.TableDefs.Delete stLocalTableName
End If
Next
Dim MyNewIP As String
MyNewIP = Nz(DLookup("NewIP", "T_IP"), 0)
If Len(stUsername) <> 0 Then
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & MyNewIP & " ;DATABASE= mydb;Trusted_Connection=No"
Else
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & MyNewIP & " ;DATABASE=mydb;UID=hr;PWD=mypwd"
End If
Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
CurrentDb.TableDefs.Append td
AttachDSNLessTable = True
Exit Function
AttachDSNLessTable_Err:
AttachDSNLessTable = False
MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description
End Function