I am trying to simplify my code, having a module which contains all DB connection functions in one Access, so this is what I've already done:
Module "DB"
Public Function connect() As String
Dim cn As ADODB.connection
cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=system;Data Source=localhost; User Id= root;Password= root;"
connect = cn
End Function
Public Function sql(cn As String, query As String) As String
Dim rs As ADODB.Recordset
cn.Open
Set rs = cn.Execute(query)
cn.Close
sql = rs
End Function
Event when I click in a button
Private Sub btn_run_Click()
conexao = connect()
result = sql(conexao, "SELECT TOP 1* FROM MIS.MP_BASE_ACOES")
End Sub
Here is what my Access as an error: Translating to en -> "Compilation error: The type defined by the user wasn't defined"
What am I doing wrong? Is that the correct way to define a connection function?
PS: There's no error in ConnectionString, I just changed some content because it is confidential.
Edit1: Following FunThomas, I really have forgotten to mark all the references like ActiveX from my project, but it still not working, now with this error: "Uncompatible argument ByRef"