Leer datos de una base de datos de SQL Server en Visual Basic en MS Access

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

Have you set up linked tables? When you say VB do you mean VBA? -

VBA is the one available in Access, isn't it? So, yeah. VBA. I have set up linked tables -

1 Respuestas

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

Or

sSQL = "SELECT ID, ABoolean FROM dbo_table_1 WHERE ABoolean=True"
Set rs = CurrentDb.OpenRecordset(sSQL)
rs.MoveLast
Debug.Print rs.RecordCount

Or

Debug.Print DLookup("Aboolean", "dbo_table_1", "ID=37")

Respondido 30 Jul 12, 11:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.