What's the best way to read data from a SQL Server database in VB from MS Access?
I have a SQL Server database set up and I'm doing the forms etc. in Access. Now I need to read a boolean value and do so in VB.
I'd like to do that without opening a new connection. Is that somehow possible?
preguntado el 30 de julio de 12 a las 10:07
You can run a query against a linked table. As far as I know, the usual choice for Boolean in SQL Server is bit:
SELECT dbo_Table1.ID, dbo_Table1.ABoolean FROM dbo_Table1 WHERE dbo_Table1.ABoolean=True
In MS Access, True displays as -1 and in SQL Server it displays as 1.
The query can also be run through VBA, if that is what you need to do.
Dim rs As DAO.Recordset Set rs = CurrentDb.OpenRecordset("dbo_table_1") Do While Not rs.EOF If rs!ABoolean = True Then Debug.Print rs!ID End If rs.MoveNext Loop
sSQL = "SELECT ID, ABoolean FROM dbo_table_1 WHERE ABoolean=True" Set rs = CurrentDb.OpenRecordset(sSQL) rs.MoveLast Debug.Print rs.RecordCount
Debug.Print DLookup("Aboolean", "dbo_table_1", "ID=37")