Results 1 to 8 of 8

Thread: simple inventory help.. please

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2021
    Posts
    2

    simple inventory help.. please

    hi ya'll..

    i'd like a lil help with something very small if possible.. there will be other things in the db to grab info from.. but this will help me get started. thanks in advance

    my objective is to connect to a DB and retrieve simple info... for me this will be a learning curve.. so here are the deets:

    1.) connect to a db
    2.) retrieve info from db

    here is my sample code:
    Attached Files Attached Files

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2021
    Posts
    2

    Re: simple inventory help.. please

    eventually i will add like freezers and other equipment. for now i just want to call what i have on hand atm

    thanks

  3. #3
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,433

    Re: simple inventory help.. please

    Without having to download the zip, you perhaps could clarify what you are using (so we can decide if we are interested)
    Are you using Access DB (which year)
    Are you using ADO ?
    Are you using Data control and binding (if you are, I am NOT interested)
    If you are using the Data Environment then none of us are interested (except dilettante)
    Rob
    PS I thought it was very brave of me to pick on dilettante, BUT with what is happening in the following posts, he might not notice.
    Last edited by Bobbles; Jan 21st, 2021 at 11:18 PM.

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,708

    Re: simple inventory help.. please

    I see you are using 2002/2003 MS Access (.mdb file).

    First thing you have to do is go to References and add: Microsoft ActiveX Data Objects X.X Library (2.8 should be all you will need) (References is on the menubar under Project).

    Then you should set some variables (if this is a one-form learning project, just put them at the top of the Form (THE FIRST LINE IN YOUR FORM should be OPTION EXPLICIT (If it is not there (it is a setting you can do in VB6), then simply type that in on the first line) . Then declare some variables like this:

    Code:
    Dim cnn as Adodb.Connection
    Dim rs as Adodb.RecordSet
    (and as you are new, if you Dim cmd as Adodb.Command, it might help you debug what your sql is going to be going to get stuff from (and put stuff in) your tables.
    Then, in Form_Load (or in a separate Subroutine--which you would call in Form_Load), you need to make a connection to your database.

    Here is an example of how I do it:

    Code:
        Set cnn = New ADODB.Connection
        With cnn
            .Provider = "Microsoft.Jet.OLEDB.4.0" 'connecting to 2002/2003 Access
    '        .Provider = "Microsoft.ACE.OLEDB.12.0"  'connecting to an MS ACCESS 2007 database  'notice this is commented out...if you were using .accdb files, you would use this instead of the previous line.
            .ConnectionString = "User ID=Admin;password= ;" & " Data Source=" & App.Path & "\inventory.mdb;"  'I am using App.path as an EXAMPLE, you may want to do something different
            .CursorLocation = adUseClient
            .Open
        End With

    Now, once you have connected to your database, things you can do to RETRIEVE information might look like this:

    Code:
        Set cmd = New ADODB.Command   
            Set cmd.ActiveConnection = cnn
        cmd.CommandText = "select * from YOURTABLENAME"   'This is very simple, and normally you don't use the asterisk (*), but rather JUST the field names from which you want to retrieve information
    'I normally do it this way, with cmd.commandtext, because I can see the actual query going to by database by using Debug.Print, like this:
    
    Debug.Print cmd.commandtext
        Set rs = cmd.Execute
    
    'Now you have  a recordset filled, you want to do something with it, like display it in a control on your form
        'You could do something like this:
        Do While Not rs.EOF
              list1.additem (rs!itemName)   'where itemName is a field name in your table 
              rs.movenext
        loop
    I hope this at least gets you STARTED...But, if I were you, I'd do a lot of reading of VB6's Help, Search for examples on this forum, as well as on Google.

    Good Luck.

    (Welcome to the Forum)

    Sam Brown

    PS---YOU MUST HAVE YOUR DB SET UP FIRST, of course!!!!
    Sam I am (as well as Confused at times).

  5. #5
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,433

    Re: simple inventory help.. please

    I dug around in my store of VB6 projects, and found this one.
    It came from PSC (may it rest in pieces)
    It is a tutorial using an Access DB, and pure ADO code (like Sam was using)
    (NOT using clunky Data Controls / Binding ETC)
    It got high praises. The zip includes a .MHT copy of the PSC web page.
    (You can open .mht saved web pages in IE, or in FF if you 'install' a suitable extension)

    Rob
    Attached Files Attached Files

  6. #6

  7. #7
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,692

    Re: simple inventory help.. please

    Bans issued for insulting behaviour and suspected creation of duplicated accounts (all coming from the same IP address)

    Ricoplush, I haven't banned your account on the basis that you might all simply be posting from the same academic location and your initial question does appear to have been asked in good faith. If that is the case you might want to find new friends because the ones you have aren't helping you make your case. But welcome to the forum and I hope you can find help and a home here.

    Do understand that, while we don't have a policy to dictate how much or how little help our members will give each other, we do have a culture. We try not to spoon feed people because, in the long run, it does them very little good. Instead we'll try to point you in the right direction, answer specific questions you have and help you get past specific bugs you might encounter. Also bear in mind that our members help each other because they enjoy it and they're nice guys. They're not being paid and do this because they like to help. As such, if you're going to ask questions, the onus is on you to make their life as easy as possible - it's the best way to get them to help you.

    Expecting members to download a zip file is a bad idea. It labour intensive for us and we can't know what's in that zip until we open it, at which point we might discover it's a malicious program (it's happened before). For those reasons most people won't download zips so won't help you.

    Bobbles questions were very reasonable. Different members have different areas of expertise and may or may not be able to help depending on what technologies you are using. Providing them with as much information as possible will allow those who can't help to skip over your question and help those who can to zero in on your thread.

    I suggest you look in particular at SamOscarBrown's post. It's excellent, well commented and he shows you exactly what you need to do. If there any bits of it you don't understand then ask and I'm sure he will be happy to explain.

    There is an excellent sticky thread in the database section that you should check out. In particular there's a tutorial in there by Mendhak that I learned database programming from back in the day.



    I'm about to clean up this thread.
    Last edited by FunkyDexter; Jan 22nd, 2021 at 05:38 AM.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,708

    Re: simple inventory help.. please

    What an excellent example, Bobbles/wqweto! I had never seen this before. It taught me some stuff I did not know. Even though my way of doing things 'works', I can see where, from that example, I might have pitfalls (and/or errors) if certain situations arise. One thing for OP (and others), look carefully at the Provider. Author uses 3.5.1...which I don't have, but rather 4.0 (with Access 2002/2003). So, if OP is using this version of Access, may need to change that line.

    Thx FD!

    Sam
    Sam I am (as well as Confused at times).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width