Prob with Adding something to Combo with another form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I have a combo box on a form, and I want to be able to add something to the
table it's getting the values from if they type in something that's not on
the list. I put this code on the combo box:

Private Sub ProjNumCombo_NotInList(NewData As String, Response As Integer)

If MsgBox("Do you want to add a project number to the list?", _
vbDefaultButton1 + vbYesNo) = vbYes Then
DoCmd.OpenForm "frmAddProject", , , , acFormAdd, acDialog
Response = acDataErrAdded
Else
Response = acDataErrContinue
Me!ProjNumCombo = Null
Me!ProjNumCombo.Dropdown
End If

End Sub

This code works and asks if I want to add the new project number. But...
when it brings up the form "frmAddProject" the form is completely blank.
There isn't a space to type in the project number and the command button to
add the project number isn't there. When I open the form independently it
opens just fine and everything displays. Can anyone think of what's going on?

Thanks!
Heather
 
HeatherD25 said:
Hi!

I have a combo box on a form, and I want to be able to add something
to the table it's getting the values from if they type in something
that's not on the list. I put this code on the combo box:

Private Sub ProjNumCombo_NotInList(NewData As String, Response As
Integer)

If MsgBox("Do you want to add a project number to the list?", _
vbDefaultButton1 + vbYesNo) = vbYes Then
DoCmd.OpenForm "frmAddProject", , , , acFormAdd, acDialog
Response = acDataErrAdded
Else
Response = acDataErrContinue
Me!ProjNumCombo = Null
Me!ProjNumCombo.Dropdown
End If

End Sub

This code works and asks if I want to add the new project number.
But... when it brings up the form "frmAddProject" the form is
completely blank. There isn't a space to type in the project number
and the command button to add the project number isn't there. When I
open the form independently it opens just fine and everything
displays. Can anyone think of what's going on?

Thanks!
Heather

A form's detail section will be blank if there are no records to display
and either the form's properties or its recordsource are such that no
records can be added; for example, if AllowAdditions = No, or the
form's recordsource query is not updatable. You're opening the form
with the acFormAdd option, so we know there will be no records to
display. The remaining question is, does the form (when first opened)
permit you to add records? If this is a form that doesn't allow
additions directly in the detail section, but instead requires you to
type in a project number and click an Add button, that may be the
problem.

It's possibly your problem would be added by removing the acFormAdd
argument from the OpenForm call. As an alternative, you could change
the design of the form itself so that the controls you mention -- the
project number text box and the "add" button -- are in the form header
section instead of the detail section. Then they will appear even if
the detail section is blank.
 
I checked the form and AllowAdditions = Yes. Also, it's supposed to be
adding a row to a table, so I don't think it's a problem with the
recordsource query not being updatable. I'm fairly new to Access, though, so
I could be wrong. It will let me add a new record when I open the form
through the Access window. It's when I open it from the other form (using
the code I posted earlier) that I get the problem.

I tried removing the AcForm Add argument and it didn't work. I also tried
putting the project number text box and the control in the header section.
They show up now, but I can't type anything in the text box. It doesn't
allow me to type anything.

Do you have any other ideas I could try?

Thanks!!
Heather
 
One more thing to ask -- do you think I'm getting the problem because my
original form is still open? How would I write the code to close my form
"frm Project Master - TEST" when I open my form "frmAddProject"??
 
HeatherD25 said:
I checked the form and AllowAdditions = Yes. Also, it's supposed to
be adding a row to a table, so I don't think it's a problem with the
recordsource query not being updatable. I'm fairly new to Access,
though, so I could be wrong. It will let me add a new record when I
open the form through the Access window. It's when I open it from
the other form (using the code I posted earlier) that I get the
problem.

I tried removing the AcForm Add argument and it didn't work. I also
tried putting the project number text box and the control in the
header section. They show up now, but I can't type anything in the
text box. It doesn't allow me to type anything.

Do you have any other ideas I could try?

I'm puzzled at the moment. Is there any code in the Open, Load, or
Current events of frmAddProject? What are the the form's other
"Allow..." properties set to?
 
HeatherD25 said:
One more thing to ask -- do you think I'm getting the problem because
my original form is still open? How would I write the code to close
my form "frm Project Master - TEST" when I open my form
"frmAddProject"??

[frm Project Master - TEST] is the name of the form from which you are
opening frmAddProject? Since you're opening frmAddProject from a
NotInList event, it wouldn't make sense to close the form that event is
firing in, just to go add a new project.
 
There aren't any events coded in the form. Also, all of the Allow fields are
set to "Yes". Anything else you can think of?
 
HeatherD25 said:
There aren't any events coded in the form. Also, all of the Allow
fields are set to "Yes". Anything else you can think of?

No, I'm stumped. If you'd like to send me a cut-down copy of your
database, containing only the elements necessary to demonstrate the
problem, compacted and then zipped to less than 1MB in size (preferably
much smaller) -- I'll have a look at it, time permitting. You can send
it to the address derived by removing NO SPAM from the reply address of
this message.
 
Back
Top