Solved

VB and access database help!

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 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