Results 1 to 6 of 6
  1. #1
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295

    Correct Query to generate a form

    I have a button on a form such that when pressed it is to open another form by a query. The query I am using is:

    Private Sub Command17_Click()
    DoCmd.OpenForm "Edit Signin", acNormal, , "OfficerName = " & WorkersName
    End Sub




    OfficerName is a field in the "Edit Siginin" Form, and WorkersName is a global Variable.



    My error message is : Syntax error ( Missing Operator ) in query expression 'OfficerName = Hector Belle'

    Can anyone assist

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    Code:
    DoCmd.OpenForm "Edit Signin", acNormal, , "OfficerName = '" & WorkersName & "'"
    Add red edit. String variables need to be enclosed in single quotes.

  3. #3
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Thanks Davegri. It's working fine.

  4. #4
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    However if I add a little more I have an error message "Mismatched data type:

    Private Sub Command17_Click()
    DoCmd.OpenForm "Edit Signin", acNormal, , "OfficerName = '" & WorkersName & "'" And "Datevalue(DateCreated) =# " & Date & "#"
    End Sub


    Can you also advise on this problem?

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    Try
    DoCmd.OpenForm "Edit Signin", acNormal, , "OfficerName = '" & WorkersName & "' And Datevalue(DateCreated) =# " & Date & "#"

  6. #6
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Thanks. It is working fine. But as you can see I almost made it. Thanks to these forums I am coming of age.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-12-2014, 06:41 AM
  2. Using Multiple Fields in Form to Generate Query
    By crawfish124 in forum Forms
    Replies: 4
    Last Post: 06-04-2014, 10:39 AM
  3. Replies: 0
    Last Post: 06-03-2014, 05:15 AM
  4. Replies: 4
    Last Post: 03-05-2012, 10:20 AM
  5. Replies: 9
    Last Post: 06-26-2011, 09:14 PM

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