Results 1 to 7 of 7
  1. #1
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110

    VBA Where Clause not bringing up the correct record


    Hello all,

    I'm having difficulties with what should be a simple open form command. My goal is to open frmVendor on the same record as cldVendorDS in the dblClick event of tboVendorName. frmVendor is in form view and cldVendorDS is in data sheet view as well as a subform on frmFilterVendor. Both frmVendor and cldVendorDS use tblVendor as their record source.

    I'm using the following code, but getting strange results.

    Code:
    Private Sub tboVendorName_DblClick(Cancel As Integer)Dim sWHERE As String
        sWHERE = "[VendorID] = " & Me.VendorID
        DoCmd.OpenForm "frmVendor", , , sWHERE
    End Sub
    frmVendor does open, but on record 2. Record 1 is the record i'm trying to open to. The other strange part is none of the other records are there. There is only record 1, the record I wish to open to and record 2, a new record and the one that opens with my event.

    Please let me know if you see where I've gone wrong with my code.

    Thank you for looking,

    John

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try setting a breakpoint or using this to test what's in the variable:

    BaldyWeb-Immediate window
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Paul,

    Thank you for the advice. I'm not familiar with the immediate window. Thank you for the link, I'm going to see if I can get this figured out.

    Have a nice day

  4. #4
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    I'm working with the immediate window and after switching my code around with no luck I've produced the following SQL lines.

    Code:
    [VendorID] = 5[VendorID] = Coeur d' Alene Paving
    [VendorID] = Consolidated Supply'
    [VendorID] = 'Consolidated Supply'
    [VendorID] = City of Coeur d' Alene
    [VendorID] = 4
    [VendorName] = 3
    [VendorName] = Consolidated Supply
    [VendorName] = 6
    [VendorID] = 4
    I assume (I don't know SQL)
    Code:
    [VendorID] = 5
    would produce the results I'm after, but this just opens frmVendor on the blank record number 2 with the correct record as number 1.

    Any further ideas as to what I'm doing wrong?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    I'm such a dummy.

    I had
    Code:
    DoCmd.GoToRecord , , acNewRec
    in the on open event for frmVendor. Once I removed this everything works fine.

    Thank you again for helping me Paul.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, glad you got it sorted.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 03-31-2014, 11:10 AM
  2. Replies: 1
    Last Post: 11-10-2013, 05:25 PM
  3. Replies: 1
    Last Post: 05-31-2013, 11:02 AM
  4. Find Record with a While Clause (filter)
    By geraldk in forum Programming
    Replies: 1
    Last Post: 02-01-2013, 04:38 PM
  5. cannot pull the correct record
    By simba in forum Reports
    Replies: 1
    Last Post: 11-30-2010, 10:45 AM

Tags for this Thread

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