Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cmd Close Question

Posted on 2008-10-12
6
Medium Priority
?
357 Views
Last Modified: 2013-11-28
In what way can I utilize the attached code in the btnClose command to reset the three major forms namely: frmS, frmW and frmT:

FrmS, FrmW and FrmT are designed as follows:
         Allow Edit = No
      Allow Deletion = No
     Allow Addition = Yes
     Data Entry = Yes.

Funny enough the code works fine just for one main form "frmS" when tested but when the code was nested with the remaining two forms, it gave errors.

Brief Description:
"frmSearch" is a popup form that loads atop each of the main forms  frmS, frmW and frmT.

"frmSearch" is used to find record to be displayed or loaded unto each of the main forms.
However, when user attempts to close "frmSearch" whem loaded on top of each of the main forms, user usually gets a compile error: "Type Mismatch.

on....
Set frm = Forms(Me.OpenArgs)

Additionally, user gets another error that says the main form Is Not Loaded (even though the main form are each loaded when in use) .

Debug usually highlight the loaded main form in question...
e.g..
If Not Form!frmS.Dirty Then


Is there any way to correct the error such that the fucntion would function as designed.
I hereby attach the "FULL" code for all the three main forms per my most recent test

In addition the openarg rference below is utilized in "frmSearch" itself at the "cmdFind" code without any error. The error is limited only to the btnClose.

Set frm = Forms(Me.OpenArgs)
Set frm = Forms(Me.OpenArgs)
        If IsLoaded("frmS") Then
            If Not Form!frmS.Dirty Then
 
                frm.Undo
                frm.AllowAdditions = True
                frm.AllowEdits = False
                frm.AllowDeletions = False
                frm.DataEntry = True
        
        If IsLoaded("FrmSearch") Then
            DoCmd.Close acForm, "FrmSearch", acSaveNo    
    Else
        'Nothing to Reset
            If IsLoaded("FrmSearch") Then
                DoCmd.Close acForm, "FrmSearch", acSaveNo
            End If
        End If
    End If

Open in new window

Search-Form.txt
0
Comment
Question by:billcute
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 22700254
Hi Bill,
How are you?
This link tells you what you have to do:  http://msdn.microsoft.com/en-us/library/bb214249.aspx
To make a form, report, or control active, you must use the SelectObject method of the DoCmd object.
http://msdn.microsoft.com/en-us/library/aa220730(office.11).aspx
______________________________
Set frm = Forms(Me.OpenArgs)
DoCmd.SelectObject acForm, frm.name, True   '<<<<<makes form the active form
------------------------------------------------
You can also test to see if a form is the active form in lieu of testing to see if it is loaded
If Screen.ActiveForm.Name = "frmS" Then
0
 
LVL 4

Author Comment

by:billcute
ID: 22709967
Hi puppydogbuddy:
Where should I place your suggested code... "DoCmd.SelectObject acForm, frm.name, True " 
in my code per my code suggestion in the attached code Snippet?
0
 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 2000 total points
ID: 22711565
Hi Bill,
Attached is my take on your code as I understand it.  You did not provide a sample DB to test, so it is not tested.  Let me know if I am misinterpreting anything.

PDB
Dim strSearch As String
Dim frm As Form
 
 
Private Sub btnClose_Click()
    
        If Len(Me.OpenArgs & vbNullString) > 0 Then
            Set frm = Forms(Me.OpenArgs)
        End If
        
        If IsLoaded("frmS") Then
            DoCmd.SelectObject acForm, "frmS", True
            If Not Form!frmS.Dirty Then
 
                frm.Undo
                frm.AllowAdditions = True
                frm.AllowEdits = False
                frm.AllowDeletions = False
                frm.DataEntry = True
            End If
        End If
        
        If IsLoaded("frmW") Then
            DoCmd.SelectObject acForm, "frmW", True
            If Not Form!frmW.Dirty Then
 
                frm.Undo
                frm.AllowAdditions = True
                frm.AllowEdits = False
                frm.AllowDeletions = False
                frm.DataEntry = True
            End If
        End If
        
        If IsLoaded("frmT") Then
            DoCmd.SelectObject acForm, "frmW", True
            If Not Form!frmT.Dirty Then
 
                frm.Undo
                frm.AllowAdditions = True
                frm.AllowEdits = False
                frm.AllowDeletions = False
                frm.DataEntry = True
            End If
        End If
 
        If IsLoaded("FrmSearch") Then
            DoCmd.Close acForm, "FrmSearch", acSaveNo
        End If
End Sub

Open in new window

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 22711579
oops, typo on line 36:
frmW should be frmT
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 22712609
bill,
I seem to remeber that your search form is loaded in dialog mode.  If that is the case, you may need to unload it at the beginning instead of at the end like I have it above.
0
 
LVL 4

Author Comment

by:billcute
ID: 22806860
poppydogbuddy:

If you dont mind please provide you second opinion at the links below. I still have some glitches with the code at the listings.

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Forms/Q_23826037.html

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Forms/Q_23828006.html

Regards
Bill
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question