Results 1 to 2 of 2
  1. #1
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169

    Open a second form to the record selected on the first form

    I have been using the following code from Paul Baldy to open a form at the record selected from the first form.
    Code:
    Dim rs As Object
    Dim lngBookmark As Long
     
    'set a variable to the current record
    lngBookmark = Me.txtEmpID
    'open the new form
    DoCmd.OpenForm "frmEmployeesDetail"
     
    'take it to the selected record
    Set rs = Forms!frmEmployeesDetail.RecordsetClone
    rs.FindFirst "EmpID = " & lngBookmark
    Forms!frmEmployeesDetail.Bookmark = rs.Bookmark
     
    Set rs = Nothing
    This works well when the variable is a number. I need to tweak the code to open another form based on a text variable. I thought all I needed to do was change
    Dim lngBookmark As Long to: Dim lngBookmark as String


    Here is my code:
    Code:
     Dim rs As Object
     Dim lngBookmark As String
    'set a variable to the current record
     lngBookmark = Me.ItemCode
    'open the new form
     DoCmd.OpenForm "frmQuestionSummary"
     DoCmd.Close acForm, "frmQuestionSummaryCOUNSEL"
    'take it to the selected record
     Set rs = Forms!frmQuestionSummary.RecordsetClone
     rs.FindFirst "ItemCode = " & lngBookmark
     Forms!frmQuestionSummary.Bookmark = rs.Bookmark
      Set rs = Nothing 
    I am getting an error message saying that Jet engine does not recognize my variable as a valid field name or expression. Can anybody see where I have made a mistake in my code? Thanks

  2. #2
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    Answered my own question. Needed to change
    Code:
    rs.FindFirst "ItemCode = " & lngBookmark
    to:
    Code:
    rs.FindFirst "ItemCode = '" & lngBookmark & "'"

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

Similar Threads

  1. new record open form
    By tubar in forum Forms
    Replies: 5
    Last Post: 03-31-2011, 12:33 PM
  2. If record does not exist, open add new record form
    By RobertIngles in forum Programming
    Replies: 2
    Last Post: 02-01-2011, 08:47 AM
  3. Replies: 1
    Last Post: 10-13-2010, 12:40 PM
  4. Replies: 1
    Last Post: 05-16-2009, 08:47 AM
  5. Loading the form with selected record
    By emilylu3 in forum Access
    Replies: 1
    Last Post: 12-09-2005, 07:49 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