Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transferdatabase - problem with event/VBA transfer

Status
Not open for further replies.

qdc

Programmer
Dec 14, 2004
5
0
0
US
I am stumped over what seens like a simple issue.

I create a new database using the following:

Dim strPath As String
Dim wrkDefault As Workspace
Dim dbsNew As DAO.Database

'capture the path name
strPath = [Export_Path_Entire].Value
'MsgBox "thePath is " & strPath

' Get default Workspace.
Set wrkDefault = DBEngine.Workspaces(0)

' Make sure there isn't already a file with the name of
' the new database.
If Dir(strPath) <> "" Then Kill strPath

' Create a new database
Set dbsNew = wrkDefault.CreateDatabase(strPath, dbLangGeneral)

Then I create a table, transfer a form and report and copy a form into the new database using the following:

Dim strExportPath As String

If Right(strPath, 4) = ".mdb" Then
strExportPath = strPath
Else
strExportPath = strPath & ".mdb"
End If
'===================================================================================================================
'create the report list in the new database
DoCmd.RunSQL "SELECT Reporting_list_tbl.* INTO Reporting_list_tbl IN '" & strExportPath & "' FROM Reporting_list_tbl;"
'===================================================================================================================
'export the report into the new database
Dim stRptName As String
stRptName = "HIV Status report"
DoCmd.TransferDatabase acExport, "microsoft access", strExportPath, acReport, stRptName, stRptName
'===================================================================================================================
'export the form into the new database
Dim stFrmName As String
stFrmName = "HIV_status_frm"
DoCmd.TransferDatabase acExport, "microsoft access", strExportPath, acForm, stFrmName, stFrmName
'===================================================================================================================
DoCmd.CopyObject strExportPath, , acForm, "menu_report_frm"

Here is the problem...I cannot use any of the events associated with the forms in the new database. I cannot even open the VBA window. When I try to click on a button on either form I get "The expression On Click event that you entered as the event property setting produced the following error: error accessing file. Network connection may have been lost..."

Is there any way to assure that the code associated witrh the forms gets transferred into the new database?

Thanks.
 
qdc,

Quick item.. Are you using "code" that is not part of the form? If so you will have to transfer those modules seperatly.

Try to bring up your form is design mode and see what "code" or functions you are referencing.

I hope this helps..

Good Luck...
 
Hitech,

Thanks for the response.

There are two buttons on the "menu_reports_frm". The code associated with the On Click event for each button is below.


Option Compare Database
-----------------------------------------------
Private Sub EditRecordsButton_Click()
On Error GoTo Err_EditRecordsButton_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "HIV_status_frm"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_EditRecordsButton_Click:
Exit Sub

Err_EditRecordsButton_Click:
MsgBox Err.Description
Resume Exit_EditRecordsButton_Click

End Sub
----------------------------------------------------------
Private Sub PrePrintReportButton_Click()
On Error GoTo Err_PrePrintReportButton_Click

Dim stDocName As String

stDocName = "HIV Status report"
DoCmd.OpenReport stDocName, acPreview

Exit_PrePrintReportButton_Click:
Exit Sub

Err_PrePrintReportButton_Click:
MsgBox Err.Description
Resume Exit_PrePrintReportButton_Click

End Sub

When I click on either button I get the error: "error accessing file. Network connection may have been lost..."

If I open the form in design view and click on the elypsis (sp?) next to the [Event Proceedure] on the On Click event, I get a blank grey VBA window. Seems like there is no code at all associated with the form????
 
qdc,

Another quick note. I know with a table that you must specity the "structureonly" paramter. Try to use this parameter with your form. That may bring the VBA "data".

I will look further.

Let me know..

Good Luck...
 
qdc,

I thing I jumped the gun. I believe that will not work.

Hmmm.

I'll check something else.

 
Thanks HitechUser,

I believe that the default is structureonly = false. But thanks for the suggestion. I'll give it a try and post the results.
 
qdc,

Can you try something. Create a new database from access using the menu. (not in code). Close this empty database. Open your original database and use the menu to export your form into the empty database. Close this database. Now open your new database and open the form in design mode and see if your VB code is there.

This will at least see if there is something "funny" in the screen.

Let me know..
 
HitechUser,

structureonly = false has no effect.

Thanks
 
HitechUser,

I get the same error and missing code. Any suggestions as to why?
 
qdc,

Man what are you doing to me!!! (Just kidding).

Do you have anything associated to the OnOpen property? Is there are recordset or table associated with this form?

Unfortunatly it will be difficult to "quess" the many different possiblities. Does this form compile correctly in the old database?

Try using the Debug.Print to display the forms OnOpen property. See example.

Debug.Print Reports("Purchase Order").OnOpen

Try exporting a "simple form" or a new one using your code or the menu and see if that works. I believe your code is fine. You need to determine what is unique about your form.


Not sure where to go from here.

Keep me posted..



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top