Solved

VB and access database help!

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

911 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