So i managed to connect Sage to my access database which is great but every time i close the database and open it up again i have to login again manually is there anyway of storing that data in Access? Be it via a variable or a table because clearly access can save the login information somewhere because i only need to login once.
Edit - added login connect details
Sub login_Click()
Dim sagedb As Database
Dim accessdb As Database
Dim rs As Recordset
Dim strConnect As String
Set sagedb = OpenDatabase("Directory")
strConnect = "DSN=SageAccountsVer20;uid=xxx;pwd=xxx;"
Set accessdb = OpenDatabase("", False, False, strConnect)
accessdb.Close
Set accessdb = Nothing
Set rs = sagedb.OpenRecordset("dbo_authors")
Debug.Print rs(0)
Debug.Print "Recordset Opened Successfully"
rs.Close
sagedb.Close
Set rs = Nothing
I don't know Sage 50, but I've worked with the Sage 300 API, which is presumably similar; you can/should store an instance of your Sage session and keep it alive for as long as you need the Sage connection alive.
The session interface I've worked with needs to be initialized, and then opened; your code needs to provide a string handle, an appID, a program name and an app version to be initialized, and then when you open the session you need a userID, a password and a database name.
Here's a C# wrapper interface I'm using (referenging Sage's COM API), that shows how the values are passed:
Of course a VBA implementation will be wildly different, but the important part is this:
My calling code looks like this:
So, have your code supply a
UserId
aPassword
, aDatabaseName
, a timestamp and whateverDBLinkFlags
you need; your VBA code could look like this:Where
mySession
is a global object variable, and then whereverAPP_USERID
comes from is entirely up to you. Hard-code them in the.Open
call, make them in-code constants, or make them in-code variables and store the values in your Access database, or in an external xml configuration file, anything works; start by getting hard-coded credentials working, and then figure out a strategy to parameterize them.