Just get started - please help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I try to get a record from a table like this:
Private Sub Tekst0_Exit(Cancel As Integer)
Dim con As Connection
Dim rs As Recordset
Dim bruger As String
bruger = Tekst0.Text
Dim strsql As String
strsql = ("select * from bruger where navn = '"&bruger&"'"), con

rs.Open (strsql)

If Not rs.EOF Then
MsgBox ("Du er " & rs.Status)
Else
MsgBox ("Du har ikke ret til denne side")
End If
End Sub

I know this is wrong so can someone help just to get started, then i believe
i can go alone with this, i'm normally using Asp .

Alvin
 
Try:

Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim bruger As String
bruger = Tekst0.Text
Dim strsql As String

Set con = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")

con.Open "your_database_connection_string"
rs.Open "select * from bruger where navn = '"&bruger&"'"
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
Thanks

But shall i use all this
I understand i shall use this if i wanr to connect to another DB
but i have open my access working in access so why shall i
use a ADODB.Connection

I don't understand this

Alvin
 
The Recordset object needs to be told what Connection to use. If you've got
an existing Connection object open, you can use that, but you still must
associated that Connection object to the Recordset object you're creating in
your routine.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 
If your code and data (or linked tables) are in the same MDB or ADP, you can
use CurrentProject.Connection. For example ...

Public Sub ListData()

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM Classification", CurrentProject.Connection
Do Until rst.EOF
Debug.Print rst.Fields(0)
rst.MoveNext
Loop
rst.Close

End Sub

Otherwise, when the code is execting in an MDB or ADP that does not contain
or link to the data, you need to create and open the connection, much as you
would in ASP ...

Public Sub ListExternalData()

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\Microsoft
Office\OFFICE11\SAMPLES\Northwind.mdb;" & _
"Persist Security Info=False"
cnn.Open
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM Employees", cnn
Do Until rst.EOF
Debug.Print rst.Fields(1)
rst.MoveNext
Loop
rst.Close
cnn.Close

End Sub
 
Thanks
Now i understand

Just one more if you can help
In my table i have a field name: "sjov"
then i want to see what in this fild
and in my way i want to write
rst.sjov

But this don't work????

Best regards alvin
and thanks for the help
 
Try using bang (!), instead of dot (.): rst!sjov



I think you can also use: rst.Fields("sjov")
 
Back
Top