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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.Save acForm (...) will not work after adding control through VBA

Status
Not open for further replies.

Dor100

Technical User
Apr 9, 2001
279
US
I'm opening a subform in design view from a procedure in another unrelated form and adding a combo box control through vba. Everything works fine until I try to save and close the subform. As soon as the code reaches the line to save it, I get the following error: "Microsoft Access cannot complete this operation. You must stop the code and try again" (run-time error 29068). Consequently, the user must be prompted about whether it should be saved before closing, which I do not want. The whole idea is to do a quick change, then save and close automatically. Does anyone know why the DoCmd.Save acForm, "SubformName" would not be working? Thanks in advance if anyone knows a solution. Here's the pertinent code:


DoCmd.OpenForm "SubformName", acDesign

Dim NewComboBox As Control

Set NewComboBox = CreateControl("SubformName", acComboBox, acDetail, , fname)

Dim p As Property

For Each p In NewComboBox.Properties
If p.name = "Name" Then
p.Value = fname
End If
Next p

'Here's where it stalls, which I've had to comment out:
'DoCmd.Save acForm, "SubformName"

'This results in an unwanted user prompt:
DoCmd.Close acForm, "SubformName
 
Hi earthandfire and Dor100
I tried the code and it worked fine for me. I read a post elsewhere that implied that the database could be corrupt ... [ponder]

As a ps would:
[tt]NewComboBox.Name = fname[/tt]
be easier
 
Thanks a lot to both of you, both tips working great. I'd tried a simpler approach with the name before to no avail, but now it's smooth sailing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top