Solved

VB and access database help!

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending a email via excel using vba 6 109
Exit a vb6 apps when a calling it apps closes 15 57
MsgBox 4 71
checkbox to hide entire section 10 58
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

740 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