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: -
Function ScanObjects(strDBToScan As String)
-
-
On Error Resume Next
-
-
Dim objdb As Database, objDBToScan As Database
-
Dim doc As Document
-
Dim frm As Form
-
Dim strForm As String, strSQL As String
-
Dim ctl As Control
-
-
'This database
-
Set objdb = CurrentDb
-
-
'Target database
-
Set objDBToScan = DBEngine.Workspaces(0).OpenDatabase(strDBToScan)
-
-
'Purge current output table
-
objdb.Execute ("Delete * from t_output")
-
-
' Each doc printed is from remote DB, connection is successful.
-
For Each doc In objdb.Containers("Forms").Documents
-
strForm = doc.Name
-
Debug.Print "Processing " & strForm
-
-
' Line below opens the form in the calling database, not the target, as intended.
-
DoCmd.OpenForm strForm, acDesign, , , , acHidden
-
-
Set frm = Forms(strForm)
-
-
For Each ctl In frm.Controls
-
-
For Each prp In ctl.Properties
-
-
If Len(prp.Value) > 0 Then
-
Debug.Print objdb.Name & "," & strForm & "," & ctl.Name & "," & prp.Name & "," & prp.Value
-
strSQL = "Insert Into t_output (db_name, element_name, ctl_name, prop_name, prop_value, run_date) Values (" & _
-
"'" & Right(objDBToScan.Name, 255) & _
-
"','" & Left(strForm, 255) & _
-
"','" & Left(ctl.Name, 255) & _
-
"','" & Left(prp.Name, 255) & _
-
"','" & Left(prp.Value, 255) & _
-
"'," & Date & _
-
")"
-
objdb.Execute strSQL
-
Else
-
Debug.Print "--> Skipping " & ctl.Name & ", " & prp.Name & ", value of '" & prp.Value & "'"
-
End If
-
-
Next
-
-
Next
-
-
DoCmd.Close acForm, strForm, acSaveNo
-
-
Next
-
Debug.Print "Done."
-
-
Set ctl = Nothing
-
Set frm = Nothing
-
Set doc = Nothing
-
-
objDBToScan.Close
-
Set objDBToScan = Nothing
-
-
objdb.Close
-
Set objdb = Nothing
-
-
End Function
-
Thanks for any assistance that can be provided on this.
1 1511
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: -
Function ScanObjects(strDBToScan As String)
-
-
On Error Resume Next
-
-
Dim objdb As Database, objDBToScan As Database
-
Dim doc As Document
-
Dim frm As Form
-
Dim strForm As String, strSQL As String
-
Dim ctl As Control
-
-
'This database
-
Set objdb = CurrentDb
-
-
'Target database
-
Set objDBToScan = DBEngine.Workspaces(0).OpenDatabase(strDBToScan)
-
-
'Purge current output table
-
objdb.Execute ("Delete * from t_output")
-
-
' Each doc printed is from remote DB, connection is successful.
-
For Each doc In objdb.Containers("Forms").Documents
-
strForm = doc.Name
-
Debug.Print "Processing " & strForm
-
-
' Line below opens the form in the calling database, not the target, as intended.
-
DoCmd.OpenForm strForm, acDesign, , , , acHidden
-
-
Set frm = Forms(strForm)
-
-
For Each ctl In frm.Controls
-
-
For Each prp In ctl.Properties
-
-
If Len(prp.Value) > 0 Then
-
Debug.Print objdb.Name & "," & strForm & "," & ctl.Name & "," & prp.Name & "," & prp.Value
-
strSQL = "Insert Into t_output (db_name, element_name, ctl_name, prop_name, prop_value, run_date) Values (" & _
-
"'" & Right(objDBToScan.Name, 255) & _
-
"','" & Left(strForm, 255) & _
-
"','" & Left(ctl.Name, 255) & _
-
"','" & Left(prp.Name, 255) & _
-
"','" & Left(prp.Value, 255) & _
-
"'," & Date & _
-
")"
-
objdb.Execute strSQL
-
Else
-
Debug.Print "--> Skipping " & ctl.Name & ", " & prp.Name & ", value of '" & prp.Value & "'"
-
End If
-
-
Next
-
-
Next
-
-
DoCmd.Close acForm, strForm, acSaveNo
-
-
Next
-
Debug.Print "Done."
-
-
Set ctl = Nothing
-
Set frm = Nothing
-
Set doc = Nothing
-
-
objDBToScan.Close
-
Set objDBToScan = Nothing
-
-
objdb.Close
-
Set objdb = Nothing
-
-
End Function
-
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: - ' Include the following in Declarations section of module.
-
Dim appAccess As Access.Application
-
-
Dim strDB as String
-
-
' Initialize string to database path.
-
Const strConPathToExtDB = "C:\Test\"
-
-
strDB = strConPathToExtDB & "TestDatabase.mdb"
-
-
' Create new instance of Microsoft Access.
-
Set appAccess = CreateObject("Access.Application")
-
-
' Open database in Microsoft Access window.
-
appAccess.OpenCurrentDatabase strDB
-
-
' Open Test form.
-
appAccess.DoCmd.OpenForm "frmTest"
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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) :...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |