Cannot close a form copied by using VB

G

Guest

I've written some VB that is supposed to taka a copy of an existing form
called "Simple2Dimension", and thereafter add som more controls to it (se
code below). The copying and adding of controls seems to work, but then the
form won't close (the DoCmd.Close in the attached code). I also have problems
saving/closing the form manually (it simply won't close if I want to save the
changes), and closing it without saving gives the message:
"Microsoft Access Office cannot complete this operation. You must stop the
code and try again."
This indicates that something is running in the background, but what?

Greatful for any guidance.

Sub test()
DoCmd.CopyObject , "TestForm", acForm, "Simple2Dimension"

DoCmd.OpenForm "TestForm", acDesign
Set frm = Screen.ActiveForm
frm.RecordSource = "Employee"
sTableName = "Employee"
frm.Caption = "Form - " & sTableName

iLabelPositionX = 100
iLabelPositionY = 700
iDetailPositionX = 100
iDetailPositionY = 100

Set ctlText = CreateControl(frm.Name, acTextBox, , , "GlobalValue", _
iDetailPositionX, iDetailPositionY, 300)
Set ctlLabel = CreateControl(frm.Name, acLabel, acHeader, , "Global", _
iLabelPositionX, iLabelPositionY, 600)

DoCmd.Close acForm, "TestForm", acSaveYes
End Sub
 
M

Marshall Barton

L. Lancin said:
I've written some VB that is supposed to taka a copy of an existing form
called "Simple2Dimension", and thereafter add som more controls to it (se
code below). The copying and adding of controls seems to work, but then the
form won't close (the DoCmd.Close in the attached code). I also have problems
saving/closing the form manually (it simply won't close if I want to save the
changes), and closing it without saving gives the message:
"Microsoft Access Office cannot complete this operation. You must stop the
code and try again."
This indicates that something is running in the background, but what?

Greatful for any guidance.

Sub test()
DoCmd.CopyObject , "TestForm", acForm, "Simple2Dimension"

DoCmd.OpenForm "TestForm", acDesign
Set frm = Screen.ActiveForm
frm.RecordSource = "Employee"
sTableName = "Employee"
frm.Caption = "Form - " & sTableName

iLabelPositionX = 100
iLabelPositionY = 700
iDetailPositionX = 100
iDetailPositionY = 100

Set ctlText = CreateControl(frm.Name, acTextBox, , , "GlobalValue", _
iDetailPositionX, iDetailPositionY, 300)
Set ctlLabel = CreateControl(frm.Name, acLabel, acHeader, , "Global", _
iLabelPositionX, iLabelPositionY, 600)

DoCmd.Close acForm, "TestForm", acSaveYes
End Sub


Not 100% sure this is the problem, but for sure you have all
kinds of active references to the form and its control
objects. Try setting each of them to Nothing before trying
to close the form.
 
G

Guest

Thanks, Marshall.

It seemes that your tip worked. Sometimes you don't have to do much, just as
long as you know what to do...

/Linus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top