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

Form disappears when code runs

Status
Not open for further replies.

Moss100

Technical User
Aug 10, 2004
586
GB
Hello, I have an email form with the code below.

I am not great at code - so this may be something obvious.

When I run the code, everything works, but the form disappears. I think it may have something to do with sending the values to the log table. To be clear the form disappears, but does not close and switching out of access and back into it then displays the form again.

Does my code need tweaking in some way to make it better. All suggestions gratefully receeived,

Many thanks Mark


Private Sub btn_send_message_DblClick(Cancel As Integer)

Dim strTest As String
strTest = TestForm()

If strTest = "" Then strTest = SendMail

If strTest = "" Then

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("log", dbOpenDynaset)

rst.AddNew
rst("log date") = Now()
rst("note") = Me.[LOG_Note]
rst("landlord log ref") = Me.[LOG_landlord_log_ref]
rst("property log ref") = Me.[LOG_property_log_ref]
rst("tenant log ref") = Me.[LOG_tenant_log_ref]
rst("landlord name") = Me.[LOG_landlord_name]
rst("property name") = Me.[LOG_property_name]
rst("tenant name") = Me.[LOG_tenant_name]
rst("contractor name") = Me.[LOG_contractor_name]
rst("Log Cheque Amount") = Me.[LOG_Log_Cheque_Amount]
rst("log type") = Me.[LOG_Log_Type]
rst("log description") = Me.[LOG_Log_Description]
rst("department") = Me.[LOG_Department]
rst("email sent") = Me.[LOG_Email_Sent]
rst("email sent date") = Me.[LOG_Email_Sent_Date]


rst.Update
rst.Close

Set rst = Nothing


Me.Check100 = True

Else

MsgBox strTest

End If

End Sub
 
What are TestForm() and SendMail ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Test form checks that an email address, subject and message have been entered and Sendmail links in with a Chillcat component.

I use the form sucessfully elsewhere in my database using the INSERT method to update the log table.

I wanted to use the code below instead of the INSERT method, but when I have tried this I have come across the form problem. Thats why I was presuming there must be some problem with how the code was written - is it removing the focus from the pop up form I am using?. Thanks Mark

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("log", dbOpenDynaset)

rst.AddNew
rst("log date") = Now()
rst("note") = Me.[LOG_Note]
rst("landlord log ref") = Me.[LOG_landlord_log_ref]
rst("property log ref") = Me.[LOG_property_log_ref]
rst("tenant log ref") = Me.[LOG_tenant_log_ref]
rst("landlord name") = Me.[LOG_landlord_name]
rst("property name") = Me.[LOG_property_name]
rst("tenant name") = Me.[LOG_tenant_name]
rst("contractor name") = Me.[LOG_contractor_name]
rst("Log Cheque Amount") = Me.[LOG_Log_Cheque_Amount]
rst("log type") = Me.[LOG_Log_Type]
rst("log description") = Me.[LOG_Log_Description]
rst("department") = Me.[LOG_Department]
rst("email sent") = Me.[LOG_Email_Sent]
rst("email sent date") = Me.[LOG_Email_Sent_Date]


rst.Update
rst.Close

Set rst = Nothing

 
do you have a [formname].visible = false command somewhere in the TestForm() have to say I had the same problem with a form and it's because I left one behind as I had copied some code from another form and hadn't taken it out.

'Clever boy...'
 
How are ya Moss100 . . .

Have you tried setting breakpoints or stepping thru the code to narrow it down?

Everything looks fine save those items mentioned by PHV. Curious though ... is the recordsource of the form where the button btn_send_message_DblClick resides based on the same log table?

Your Thoughts? ...

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Moss100 said:
...When I run the code, everything works, but the form disappears...

...To be clear the form disappears, but does not close...

To be even clearer, does the Form actually pull a disappearing act, i.e. is totally gone, or does the Form background actually remain but all of the Controls (Textboxes, Comboboxes, Labels) disappear?

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
I've seen this before. When the form is set to not allow additions and there is no record selected the form disappears.
 
Actually, when the Form is Bound, New Records cannot be added, for any reason, and when there are no Records available in the Bound RecordSet.

The second condition can be due to AllowAdditions being set to No, the RecordSource being a Read-Only, Multi-Table Query or the RecordSetType being set to Snapshot.

Both the second and third conditions can be due to the user not having the appropriate privileges for the Folder where the data resides.

All of this is assuming that by "the form disappears" the OP means that the Form background remains, but all Controls (Textboxes, Comboboxes, Labels) have left town, which was what I was trying to ascertain by my original question.

But it appears that the OP has disappeared, as well as his/her Form! To be fair, I didn't realize, when I responded to this thread, that it was as old as it was. But perhaps it will help others with similar problems.

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top