473,791 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A2K: Error when opening remote DB to read controls.

1 New Member
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.Worksp aces(0).OpenDat abase(DBName) method to do this, as the Access.Applicat ion 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 1533
ADezii
8,834 Recognized Expert Expert
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.Worksp aces(0).OpenDat abase(DBName) method to do this, as the Access.Applicat ion 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
5041
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 double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
13
1970
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 ... @#$%$ Warning: Don't just try following code on any existing db. Make sure there is a copy! (I did ...) To test I created a NEW db in A2000 and just set some properties (menu StartUpOptions) Props like: AppTitle, StartUpForm,...
2
1842
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 2003 and upgraded all the other Office apps. I have all updates/service packs installed including Jet SP8. OS is XP Pro. I have a repeatable situation where opening a report with code will cause any mdb to crash every time. The following is one...
6
4756
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 appreciated. Thanks in advance
2
3090
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 part of an access projcet (ADP) and runs against SQL Server 2000. I have an bound form in endless view which contains a header with a combobox. This combobox is bound to an access query and shall allow to
13
2522
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 Error GoTo err_zoom strFormName = formName
0
3714
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) : base(message){} public FtpException(string message, Exception innerException) : base(message,innerException){}
23
2653
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 in a direction to find info on how to prevent and/or fix the db's so that these message don't pop up when the app is started. Error messages below: 1. Microsoft Jet 4.0 service pack 8 must be installed to block unsafe expressions without...
0
2601
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 Computer A had A97. They wanted both computers to be able to use the database, stored on Computer A. I can't get them to do that, and it seems to be a network problem. I installed A2K on each computer, putting it in a special directory which I...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9993
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.