473,394 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

A2K: Error when opening remote DB to read controls.

1
First off, my apologies if this topic has previously been covered.

I am in the process of creating an A2K DB (Win XP) that will open other DBs (either on local drive, mapped drives, or UNC network path). My current goal is to open all forms from the target DB, read through the controls, and if the length of the control's property is > 0 (eliminate nulls and blanks), write the value out to a table on my local DB.

I am using the DBEngine.Workspaces(0).OpenDatabase(DBName) method to do this, as the Access.Application is not exactly what I am looking for (DBs to be catalogued are quite large and have long startup scripts associated. Besides, I just want to peek inside, not run it).

I am able to successfully read through the forms collection, however when attempting to DoCmd.OpenForm(strFormName), it is attempting to open that element on the DB that is running the script (not the target).

My code:
Expand|Select|Wrap|Line Numbers
  1. Function ScanObjects(strDBToScan As String)
  2.  
  3. On Error Resume Next
  4.  
  5.     Dim objdb As Database, objDBToScan As Database
  6.     Dim doc As Document
  7.     Dim frm As Form
  8.     Dim strForm As String, strSQL As String
  9.     Dim ctl As Control
  10.  
  11.     'This database
  12.     Set objdb = CurrentDb
  13.  
  14.     'Target database
  15.     Set objDBToScan = DBEngine.Workspaces(0).OpenDatabase(strDBToScan)
  16.  
  17.     'Purge current output table
  18.     objdb.Execute ("Delete * from t_output")
  19.  
  20.     ' Each doc printed is from remote DB, connection is successful.
  21.     For Each doc In objdb.Containers("Forms").Documents
  22.         strForm = doc.Name
  23.         Debug.Print "Processing " & strForm
  24.  
  25.         ' Line below opens the form in the calling database, not the target, as intended.
  26.         DoCmd.OpenForm strForm, acDesign, , , , acHidden
  27.  
  28.         Set frm = Forms(strForm)
  29.  
  30.         For Each ctl In frm.Controls
  31.  
  32.             For Each prp In ctl.Properties
  33.  
  34.                 If Len(prp.Value) > 0 Then
  35.                     Debug.Print objdb.Name & "," & strForm & "," & ctl.Name & "," & prp.Name & "," & prp.Value
  36.                     strSQL = "Insert Into t_output (db_name, element_name, ctl_name, prop_name, prop_value, run_date) Values (" & _
  37.                              "'" & Right(objDBToScan.Name, 255) & _
  38.                              "','" & Left(strForm, 255) & _
  39.                              "','" & Left(ctl.Name, 255) & _
  40.                              "','" & Left(prp.Name, 255) & _
  41.                              "','" & Left(prp.Value, 255) & _
  42.                              "'," & Date & _
  43.                              ")"
  44.                     objdb.Execute strSQL
  45.                 Else
  46.                     Debug.Print "--> Skipping " & ctl.Name & ", " & prp.Name & ", value of '" & prp.Value & "'"
  47.                 End If
  48.  
  49.             Next
  50.  
  51.         Next
  52.  
  53.         DoCmd.Close acForm, strForm, acSaveNo
  54.  
  55.     Next
  56.     Debug.Print "Done."
  57.  
  58.     Set ctl = Nothing
  59.     Set frm = Nothing
  60.     Set doc = Nothing
  61.  
  62.     objDBToScan.Close
  63.     Set objDBToScan = Nothing
  64.  
  65.     objdb.Close
  66.     Set objdb = Nothing
  67.  
  68. End Function
  69.  
Thanks for any assistance that can be provided on this.
Mar 30 '07 #1
1 1511
ADezii
8,834 Expert 8TB
First off, my apologies if this topic has previously been covered.

I am in the process of creating an A2K DB (Win XP) that will open other DBs (either on local drive, mapped drives, or UNC network path). My current goal is to open all forms from the target DB, read through the controls, and if the length of the control's property is > 0 (eliminate nulls and blanks), write the value out to a table on my local DB.

I am using the DBEngine.Workspaces(0).OpenDatabase(DBName) method to do this, as the Access.Application is not exactly what I am looking for (DBs to be catalogued are quite large and have long startup scripts associated. Besides, I just want to peek inside, not run it).

I am able to successfully read through the forms collection, however when attempting to DoCmd.OpenForm(strFormName), it is attempting to open that element on the DB that is running the script (not the target).

My code:
Expand|Select|Wrap|Line Numbers
  1. Function ScanObjects(strDBToScan As String)
  2.  
  3. On Error Resume Next
  4.  
  5.     Dim objdb As Database, objDBToScan As Database
  6.     Dim doc As Document
  7.     Dim frm As Form
  8.     Dim strForm As String, strSQL As String
  9.     Dim ctl As Control
  10.  
  11.     'This database
  12.     Set objdb = CurrentDb
  13.  
  14.     'Target database
  15.     Set objDBToScan = DBEngine.Workspaces(0).OpenDatabase(strDBToScan)
  16.  
  17.     'Purge current output table
  18.     objdb.Execute ("Delete * from t_output")
  19.  
  20.     ' Each doc printed is from remote DB, connection is successful.
  21.     For Each doc In objdb.Containers("Forms").Documents
  22.         strForm = doc.Name
  23.         Debug.Print "Processing " & strForm
  24.  
  25.         ' Line below opens the form in the calling database, not the target, as intended.
  26.         DoCmd.OpenForm strForm, acDesign, , , , acHidden
  27.  
  28.         Set frm = Forms(strForm)
  29.  
  30.         For Each ctl In frm.Controls
  31.  
  32.             For Each prp In ctl.Properties
  33.  
  34.                 If Len(prp.Value) > 0 Then
  35.                     Debug.Print objdb.Name & "," & strForm & "," & ctl.Name & "," & prp.Name & "," & prp.Value
  36.                     strSQL = "Insert Into t_output (db_name, element_name, ctl_name, prop_name, prop_value, run_date) Values (" & _
  37.                              "'" & Right(objDBToScan.Name, 255) & _
  38.                              "','" & Left(strForm, 255) & _
  39.                              "','" & Left(ctl.Name, 255) & _
  40.                              "','" & Left(prp.Name, 255) & _
  41.                              "','" & Left(prp.Value, 255) & _
  42.                              "'," & Date & _
  43.                              ")"
  44.                     objdb.Execute strSQL
  45.                 Else
  46.                     Debug.Print "--> Skipping " & ctl.Name & ", " & prp.Name & ", value of '" & prp.Value & "'"
  47.                 End If
  48.  
  49.             Next
  50.  
  51.         Next
  52.  
  53.         DoCmd.Close acForm, strForm, acSaveNo
  54.  
  55.     Next
  56.     Debug.Print "Done."
  57.  
  58.     Set ctl = Nothing
  59.     Set frm = Nothing
  60.     Set doc = Nothing
  61.  
  62.     objDBToScan.Close
  63.     Set objDBToScan = Nothing
  64.  
  65.     objdb.Close
  66.     Set objdb = Nothing
  67.  
  68. End Function
  69.  
Thanks for any assistance that can be provided on this.
I think it would be advisable to go the Automation route - it may be the only way to go. The following code example opens a Microsoft Access database from another application through Automation and then opens a form in that database. This is just a subset of the code you will need, but it should point you in the right direction:
Expand|Select|Wrap|Line Numbers
  1. ' Include the following in Declarations section of module.
  2. Dim appAccess As Access.Application
  3.  
  4. Dim strDB as String
  5.  
  6. ' Initialize string to database path.
  7. Const strConPathToExtDB = "C:\Test\"
  8.  
  9. strDB = strConPathToExtDB & "TestDatabase.mdb"
  10.  
  11. ' Create new instance of Microsoft Access.
  12. Set appAccess = CreateObject("Access.Application")
  13.  
  14. ' Open database in Microsoft Access window.
  15. appAccess.OpenCurrentDatabase strDB
  16.  
  17. ' Open Test form.
  18. appAccess.DoCmd.OpenForm "frmTest"
Mar 30 '07 #2

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

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
13
by: Arno R | last post by:
Hi all In another thread I had problems changing db.props Another problem I encountered while testing this: db corrupt When I deleted db.props through code in a loop I could not start the db again...
2
by: Brent | last post by:
I have just installed Office 2003 and Visual Studio Tools for Office 2003, including the Developer Extensions for Access. I kept my Access 2000/MOD installation intact (I hope), installed Access...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Wolfgang Kreuzer | last post by:
Hello all, I am converting an Axs 2.0 application to a2k (I know A2K is not the most current version but Axs 2.0 support ended and A2K is supported in our company amd on every PC). The form is...
13
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
23
by: Reggie | last post by:
Hi and TIA. I developed several A2K dbs which are now being run on my clients computer which have been upgraded to Access 03. I'm not sure exactly what they mean but of you know or could point me...
0
by: Paul Brady | last post by:
I volunteer at a youth ministry agency and help them with their student database. They have two computers, both running Windows XP. Both have Office 2002 installed without Access, except that...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.