Results 1 to 6 of 6
  1. #1
    moneypennie21 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    41

    Do.Cmd.OpenForm with Where clause

    HI,



    I have a contact details form and on it I have placed an edit button which I only want to be accessed by those who have the admin password. so when clicked on i want it to ask for password and then when entered correctly open the edit contact details form in edit mode for the current record selected in the contact details form. I have tried various bits of code and have the password element working fine but I can either open the edit record form on the first record alphabetically or a blank edit contact form. this is the code I have currently which when the correct password is entered opens a blank edit contact form - Any assistance would be appreciated

    Private Sub edit_button_Click()
    Dim strPasswd


    strPasswd = InputBox("Enter Password", "Restricted Form")


    If strPasswd = "" Or strPasswd = Empty Then
    MsgBox "No Input Provided", vbInformation, "Required Data"
    Exit Sub
    End If


    If strPasswd = "Sunshine" Then
    DoCmd.OpenForm "edit_contact_form", , , "[Forms]![contact_details_form]" = "Me.Full_Name", acFormEdit
    Else
    MsgBox "Sorry you do not have access to this form", -vbOKOnly, "Important Information"
    Exit Sub
    End If


    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    the where clause refers to a field in the current form , the table/query field , ( not a path)

    DoCmd.OpenForm "edit_contact_form", , , "[state]='" & me.txtState & "'"

  3. #3
    moneypennie21 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    41
    Sorry, am quite new to Access VBA, does this mean I can't do what I am trying to do?

  4. #4
    moneypennie21 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    41
    I think I have resolved this using the OpenArgs - code as follows seems to work and opens the edit form at the correct record in edit mode which is what I wanted:

    DoCmd.OpenForm "edit_contact_form", , , , acFormEdit, , "full_name"

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    A WHERE clause is the same as is used in a query but without the word WHERE. Create a query and add a criteria, then go to SQL view and copy the criteria just as it is, that will give you the correct syntax.

  6. #6
    moneypennie21 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    41
    HI aytee111 trhanks but I think I have solved it with the OpenArgs clause as it si working exactly how I want it to now.

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

Similar Threads

  1. Openform with two criteria
    By prendergi in forum Forms
    Replies: 3
    Last Post: 05-20-2016, 03:32 PM
  2. OpenForm to specific tab
    By rivereridanus in forum Access
    Replies: 1
    Last Post: 06-28-2012, 07:32 PM
  3. Replies: 4
    Last Post: 04-11-2012, 01:47 PM
  4. What actually happens at docmd.openform
    By Beorn in forum Programming
    Replies: 4
    Last Post: 01-05-2011, 02:19 PM
  5. Getting to a tab on openform
    By Swarland in forum Programming
    Replies: 5
    Last Post: 12-12-2010, 11:22 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