Results 1 to 7 of 7
  1. #1
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124

    Close form and open another form

    Hello,
    Forum

    I am having trouble closing my frmLogin and opening frmMaster.

    When User enters wrong password. The form will close.



    What I want is to close frmLogin only when User has open frmMaster

    TIA

    Haziq
    Attached Files Attached Files

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Add the red code to your btnLogin_Click event:
    Code:
        Else
        
            MsgBox "Login UnSuccessful!"
            txtPassword = vbNullString
            Exit Sub
        End If
    Also, change your frmLog code to this:
    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub btnAddNewRecord_Click()
        Dim sSQL As String
        Dim nQty As Long
        nQty = DLookup("CurrentQty", "tblMaster", "MasterIDPK=" & MasterIDFK)
        
        Select Case Withdraw
            Case True
                If nQty - UserQty > 0 Then
                    sSQL = "UPDATE tblMaster Set CurrentQty = CurrentQty - " & [UserQty] & " WHERE MasterIDPK = " & [MasterIDFK]
                End If
            Case False
                sSQL = "UPDATE tblMaster Set CurrentQty = CurrentQty + " & [UserQty] & " WHERE MasterIDPK = " & [MasterIDFK]
            Case Else
                MsgBox "No action taken, 'Withdraw' does not contain a valid entry", vbOKOnly, "  I N P U T   N E E D E D   "
                Exit Sub
        End Select
        If Len(sSQL) > 0 Then
            CurrentDb.Execute sSQL, dbFailOnError
        Else
            MsgBox "No action taken, check your quantities for valid values", vbOKOnly, "  C H E C K   QTY   V A L U E S   "
        End If
        DoCmd.Close acForm, Me.Name
    End Sub

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try attached file:
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also note:

    EVERY code module should have these top two lines:
    Code:
    Option Compare Database
    Option Explicit

    After you do that, you can do a Debug/Compile and fix the errors.
    You have a variable not declared, "strSection" in form "frmLogin" and a misspelled argument "dbfailonerrror" in form "frmLog".


    I think you have a problem with your structure/relationships. Why is the relationship 1-to-1 between "tblDesc" and "tblMaster"??

  5. #5
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124
    Thank you guys for all your help.

    It is working the way how I visioned it.

    @ssanfu,

    June7 did point this out too.

    The reason is because I wanted to split the information about the item in another table.

    I have not make the required adjustments.

    I am going to do it now.

    Btw can I append tblDesc to tblMaster?

    @Bob Fitz, I saw what you did there in the tblemployees

    TIA

    Haziq

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Yes, you could create the fields in tblMaster, then use an Append query to copy the data.

    An alternative is to change the field "MasterIDFK" in tblDesc so it is NOT the PK field. (doesn't make sense to have the field as the PK field, but the field name has "FK" in it).
    Delete the relationship between the two tables.
    Add a new PK field (I named it DescID_PK")
    Edit the field "MasterIDFK", change the Indexed property to "Yes - Duplicates OK".
    Add the relationship. Now it should be 1-to-many.
    Click image for larger version. 

Name:	Tables1.png 
Views:	11 
Size:	74.4 KB 
ID:	32007

  7. #7
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124
    Thankyou for the speedy reply.

    I have combine both tables into one using make table query.

    I will put to practice what you have thought me.

    Thanks again.

    ---------------
    Haziq
    ---------------
    I am still trying

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 10-09-2014, 07:09 PM
  2. Replies: 2
    Last Post: 05-11-2012, 11:52 AM
  3. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  4. Replies: 11
    Last Post: 01-26-2012, 01:22 PM
  5. Open Form and Close Previous Form
    By gerrymouse1 in forum Forms
    Replies: 3
    Last Post: 04-19-2011, 05:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums