473,545 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How Open Database to search for a table using vba to display its data properties.

3 New Member
Hi Everyone,
I am working on a piece of code, that displays the properties(Name , Datatype, size & Description) of the table in the database.
Now I want to further Enhance the code.
I Have created a form in MS Access, on that form, I have 2 buttons & a text box.
One button is to select a mdb file, whom properties i want to display. Second button then stores that properties in a Excel file.
when I open the file using first button, the path of the file gets stored in the TextBox. Now what i want is that second button that generates the properties to take that path & open that database. But I couldn't able to link that path in the text box to open that database connection.

The code for both buttons is like this:
*************** *************** ***
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Command0_Click()
  4. Dim mesPath, mestab, messec As String
  5.  
  6. messec = ""
  7. Call CreateSchemaFile("\\ohsstor2\home\sluthra\My Documents\schemas\")
  8. End Sub
  9.  
  10. Private Sub Command6_Click()
  11. Dim AccessPath As String
  12. AccessPath = BrowseForfile("C:\", "MS Access Files (.mdb)|*.mdb")
  13. Text4.Value = AccessPath
  14.     If AccessPath = "" Then: MsgBox "No path provided - stopping": Exit Sub
  15. End Sub
  16.  
  17. Private Function CreateSchemaFile(sPath As String)
  18.  
  19. Dim Msg As String ' For error handling.
  20. On Error GoTo Err_ShowDescrip
  21.    Dim ws As Workspace, db As DAO.Database
  22.    Dim tblDef As DAO.TableDef, fldDef As DAO.Field
  23.    Dim i As Integer, Handle As Integer
  24.    Dim fldName As String, fldDataInfo As String
  25.    Dim dbpath As String
  26.  
  27.  
  28.  
  29.  
  30.    ' -----------------------------------------------
  31.    ' Set DAO objects.
  32.    ' -----------------------------------------------
  33.     dbpath = "Text4.value"
  34.     szConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath & "; "
  35.     SQL1 = "Select * from NADB;"
  36.     Set rst = CreateObject("ADODB.Recordset")
  37.     rst.Open SQL1, szConnStr, 1, 3
  38.     'Set db = CurrentDb()
  39.    ' -----------------------------------------------
  40.    ' Open schema file for append.
  41.    ' -----------------------------------------------
  42.  
  43.     sPath = "\\ohsstor2\home\sluthra\My Documents\schemas\"
  44.     sTblQryName = "NADB"
  45.     sSectionName = sTblQryName
  46.     bIncFldNames = True
  47.  
  48.    fname = "schema_" & sTblQryName & ".ini"
  49.  
  50.    Handle = FreeFile
  51.    Open sPath & "schema_" & sTblQryName & ".xls" For Output Access Write As #Handle
  52.    ' -----------------------------------------------
  53.    ' Write schema header.
  54.    ' -----------------------------------------------
  55.    Print #Handle, "Table : "; sSectionName
  56.    'Print #Handle, "ColNameHeader = " & IIf(bIncFldNames, "True", "False")
  57.    Print #Handle, "Created BY : SUNNY LUTHRA"
  58.    Print #Handle, "Date : "; Now
  59.    Print #Handle, "" & "Column Name" & Chr(9) & "Data Type" & Chr(9) & "Size" & Chr(9) & "Description"
  60.    ' -----------------------------------------------
  61.    ' Get data concerning schema file.
  62.    ' -----------------------------------------------
  63.       Set tblDef = db.TableDefs(sTblQryName)
  64.    With tblDef
  65.       For i = 0 To .Fields.Count - 1
  66.          Set fldDef = .Fields(i)
  67.          With fldDef
  68.             fldName = .Name
  69.             Select Case .Type
  70.                Case dbBoolean
  71.                   fldDataInfo = "Bit" & Chr(9)
  72.                Case dbByte
  73.                   fldDataInfo = "Byte" & Chr(9)
  74.                Case dbInteger
  75.                   fldDataInfo = "Short" & Chr(9)
  76.                Case dbLong
  77.                   fldDataInfo = "Integer" & Chr(9)
  78.                Case dbCurrency
  79.                   fldDataInfo = "Currency" & Chr(9)
  80.                Case dbSingle
  81.                   fldDataInfo = "Single" & Chr(9)
  82.                Case dbDouble
  83.                   fldDataInfo = "Double" & Chr(9)
  84.                Case dbDate
  85.                   fldDataInfo = "Date" & Chr(9)
  86.                Case dbText
  87.                   fldDataInfo = "Char " & Chr(9) & Format$(.Size)
  88.                Case dbLongBinary
  89.                   fldDataInfo = "OLE" & Chr(9)
  90.                Case dbMemo
  91.                   fldDataInfo = "LongChar" & Chr(9)
  92.                Case dbGUID
  93.                   fldDataInfo = "Char" & Chr(9) & "16"
  94.             End Select
  95.            flddescrip = .Properties("Description")
  96.  
  97.             Print #Handle, "" & fldName & _
  98.                              Chr(9) & fldDataInfo & Chr(9) & flddescrip
  99.          End With
  100.                Next i
  101.    End With
  102.    MsgBox sPath & fname & " has been created."
  103.    CreateSchemaFile = True
  104. CreateSchemaFile_End:
  105.    Close Handle
  106. Exit_ShowDescrip:
  107. Exit Function
  108. Err_ShowDescrip:
  109. If Err = 3270 Then
  110. flddescrip = ""
  111. Resume Next
  112. Else
  113. MsgBox (Err & ": " & Error$), , "ShowDescrip()"
  114. End If
  115. End Function
  116.  
  117.  
  118.  
  119. Private Function BrowseForfile(pstrPath, pstrFilter)
  120. Set objDialog = CreateObject("UserAccounts.CommonDialog")
  121. objDialog.Filter = pstrFilter
  122. objDialog.InitialDir = pstrPath
  123. objDialog.Flags = &H80000 + &H4 + &H8
  124. intResult = objDialog.ShowOpen
  125. BrowseForfile = objDialog.FileName
  126.  
  127.             If intResult = 0 Then
  128.             MsgBox "No file selected - Exiting"
  129.             End If
  130. End Function
  131.  
*************** *************** ****
Can Anyone Knows How to set the database path here:
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & dbpath & "; "
So that instead of defining the path of data source.
Data Source should automatically takes the value in the text box or the file I open using file dialog box.
Or Anyone Having working code for opening an mdb file & displaying the properties of the tables. & then stores it in Excel file.
Jan 8 '08 #1
1 3687
JKing
1,206 Recognized Expert Top Contributor
Hi there,

Could you not just alter your CreateSchemaFil e Function to take both an spath and a dpath. This way when you call the function you can pass in the returned value of BrowseForFile as the dpath.

Jking
Jan 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1838
by: Rob Meade | last post by:
Hi all, Ok - this leads on from speaking to a couple here and in the SQL server group... I've an application which allows the user to type in their text into a form, they add 'happy' tags around their words, the app then replaces these with the html equivalent and saves it to the database... Thus far this has been working very well.
3
2746
by: Daniel M | last post by:
I'm building a medium-scale data-entry web application, which involves creating data entry forms, record listings and detail screens for lots of database tables. Rather than designing a series of similar web pages for each table I'm looking into recording metadata about tables / columns in the database and using this to determine...
0
5803
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database which indexes computer magazine articles for personal reference. I am developing a Visual Basic.NET program whose sole purpose is to enter new...
5
1551
by: plenahan68 | last post by:
I've made a small vb.net program to read my database and delete records that are specific to my needs. Well, the program says it's complete but nothing is deleted from my database. I've listed the code below. Imports System.data.oledb Imports System.Data Public Class Form1 Inherits System.Windows.Forms.Form Public Enum etif efilename = 0
4
1896
by: visionstate | last post by:
Hi there, I'm fairly new to access and the way it works and I have been building a relatively simple database. It is basically a database where staff members can search for what training they (or others) have completed by staff name, staff group or training name. I created this using a form which had 2 text boxes and a combo box. These were...
3
2926
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news groups for years, I figure it's time for me to contribute a little bit back, maybe some people out there will find this useful. * Introduction ...
3
15974
by: toffee | last post by:
Hi all, I got a pre-formatted spreadsheet. would it be possible using js to copy the data from a table on the current webpage, open the spreadsheet and paste the content ? if so, anyone got any links or pointers? i've already tried google - but all i get is ActiveX methods which work in a very few cases.
2
3551
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in uby/Rails. I started it in Perl and gave up on Perl as I went from the 'display the database information on the web page' to the 're-display the information...
12
77947
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please give me some idea where I am going wrong ?? I just want to retrieve data from my emp_mstr table and display it using my JSP file... The table...
0
7459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7411
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7749
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5965
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5322
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3444
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
695
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.