Solved

VB and access database help!

Posted on 2004-10-19
5
167 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now