Solved

VB and access database help!

Posted on 2004-10-19
5
174 Views
Last Modified: 2010-05-02
I have a program called print manager plus, which manages printing for users. The software is built on an access database. I build a vb program to logon to the print server which docs how much you have printed. I am not strong at all in VB. What happens is the user logs in to my program which logs into the windows server containing the database. With the user name entered in the VB text field, I need to query the access database and then print out in a box a desired field or 2. Any help would be great, thanks again.

0
Comment
Question by:HSLC-INFOLAB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
RichW earned 125 total points
ID: 12349195
Here's something you can try.  Set a reference to the Microsoft ActiveX Data Object 2.x library (whichever MDAC you have installed)


This code will go out to a database on a server listed as U: and in a folder named Temp named myAccessdb.mdb.

It will then grab fields from a table named myTable and return them to textboxes.

Note:  myField1, etc. is the name of the db field.  

Rename the server and folder and database names and the fieldnames and this should work for you.

This is for Access 97.

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

    Set cnn = New ADODB.Connection
    Set rst = New ADODB.Recordset

    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=U:\" & _
       "Temp\myAccessDB.mdb"
    strSQL = "SELECT * FROM myTable"
    rst.Open strSQL, cnn

        txtTexbox1.Text = rst.Fields("MyField1")
        txtTexbox2.Text = rst.Fields("MyField2")
        txtTexbox3.Text = rst.Fields("MyField3")
        rst.MoveNext

    rst.Close
    Set rst = Nothing
    cnn.Close
    Set cnn = Nothing
0
 
LVL 2

Expert Comment

by:YSkelling
ID: 12353595
Only helping for the first answer :

Let's say your TextBox is named txtUser and the result are txtNumberOfCopy and txtCreditleft :

strSQL = "SELECT * FROM usersTable Where UserName = '" & txtUser.text & "'"
    rst.Open strSQL, cnn


        txtNumberOfCopy.Text = rst.Fields("NumOfCopy")
        txtCreditleft.Text = rst.Fields("LeftOverPaidFor")


    rst.Close
0
 
LVL 2

Expert Comment

by:YSkelling
ID: 12353611
Sorry did not finish...
Next try :


Only helping for the first answer :

Let's say your TextBox is named txtUser and the result are txtNumberOfCopy and txtCreditleft :

strSQL = "SELECT * FROM usersTable Where UserName = '" & txtUser.text & "'"
    rst.Open strSQL, cnn
      if not rst.eof    'then the user is in the DB

        txtNumberOfCopy.Text = rst.Fields("NumOfCopy")
        txtCreditleft.Text = rst.Fields("LeftOverPaidFor")
     end if

    rst.Close


maybe it is more clear, but give the point to the first one anyway ;-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question