Re: VB and Access Database.
Quote:
Originally posted by nvc944
OK I am totally new to Access, I've created 2 fields in Access
will say name Username and ID.
then I saved it.
nvc.db
So that is my access file, so now I want to call the access file I have that.
now does anyone have documentation on how to create a proper Access file.. something simple .. I can create the link with VB to the file..
thank you all
Open a new project and add a command button to the form.
Add a reference to "Microsoft ActiveX Data Objects 2.x Library"
Add this code:
VB Code:
Private Sub Command1_Click()
Dim rst As New ADODB.Recordset
Dim cnn As String, strFileName As String, strSQL As String
strFileName = "C:\Temp.mdb"
strSQL = "SELECT * FROM Login"
cnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileName
rst.Open strSQL, cnn
MsgBox rst!UserName & vbCrLf & rst!Password
Set rst = Nothing
End Sub
Of course change the filename(c:/temp.mdb), tablename(Login), and fieldnames(UserName,Password) to match your database.
That should get you started.