Results 1 to 4 of 4
  1. #1
    Artist.Anon is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    22

    Question Cannot open a Form based on a current form field value. Help!

    I have a command button on a Customer form that when clicked should open the Correspondence form and only show records belonging to that customer.



    Code:
    Private Sub btnCorrespondence_Click()
     DoCmd.OpenForm "sfCorrespondence", , , "=[CustomerID] = " & Me!ID
    End Sub
    I get an error "An expression you entered is the wrong data type for one of the arguments" (runtime error 2498)

    1. On the Customer form I have a command button with Event On Click set to Event Procedure, and links to the above code.
    2. The Customer table, ID is AutoNumber (type = Long Integer)
    3. The Correspondence table, CustomerID is Number (type = Long Integer)

    What am I doing wrong here? I have played around with expressions and force typing variables but nothing works.







    Using Windows 7 & MS Access 2010 (64 bit)

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    Code:
    Private Sub btnCorrespondence_Click()
     DoCmd.OpenForm "sfCorrespondence", , , "[CustomerID] = " & Me!ID
    End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Artist.Anon is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    22
    Well that worked, can't believe I hadn't tried that in all my variations I did.
    Thanks.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Artist.Anon View Post
    Well that worked, can't believe I hadn't tried that in all my variations I did.
    Thanks.
    You're welome. Pleased to be of help.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Browse and Open Folder Based on Matching Form Field
    By Tomfernandez1 in forum Access
    Replies: 11
    Last Post: 02-26-2013, 01:04 PM
  2. Open Current Report With Form Button
    By Rick5150 in forum Reports
    Replies: 8
    Last Post: 10-12-2011, 02:28 PM
  3. Replies: 2
    Last Post: 08-11-2011, 10:02 AM
  4. Open (sub)form linking 2 criteria on current form
    By websterh in forum Programming
    Replies: 2
    Last Post: 02-07-2011, 11:56 PM
  5. Open form to current record
    By rbpd5015 in forum Access
    Replies: 1
    Last Post: 08-28-2009, 01:53 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