Results 1 to 11 of 11
  1. #1
    Rick West is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    90

    Form/SQL

    I am running the following code in a form. It fires on the lost focus event of the field called "PNAdd" and is supposed to grab and retain "Part Description". It does not work, can you see anything wrong with this code?



    Private Sub PNAdd_LostFocus()
    Dim dbs As Database
    Dim rst As Recordset
    Dim strSQL As String
    Dim strOpenArgs As String

    Set dbs = CurrentDb
    strOpenArgs = Me![PNAdd]

    strSQL = "SELECT [Part Description] from T_PartsMaster WHERE PN = '" & strOpenArgs & "'"

    Set rst = dbs.OpenRecordset(strSQL)

    rst.MoveFirst

    'strV = rst![Part Description]
    'Form_F_PNAdd.Description = strVDesc
    Description = rst![Part Description]
    rst.Close
    dbs.Close
    End Sub

  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,640
    Define "does not work"; error? If so, what's the error and on what line? The MoveFirst line is not necessary and will throw an error if the recordset doesn't return any records.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    SteveH2508 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Chelsea, London, England
    Posts
    117
    What is Description in the line Description = rst![Part Description]?

    Is it a variable, a text box or what?

  4. #4
    Rick West is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    90
    It's just an attribute from the T_PartsMaster, like this:

    PN ,,,,,,,,,,,,,,,Description
    L77-1225,,,,,,,Bracket

    Sorry I had to use commas to keep these separated, they are 2 different fields in the table. PN is keyed.

  5. #5
    Rick West is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    90
    I have it working - somewhat. yeah! BUT as in all things, something else is broken now - the underlying form will not refresh with the new data unless I go to form design and back.

    What's the trick to get a form to requery itself when it gets focus again?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Try

    Me.Requery
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Rick West is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    90
    Tried it in several different places - nada.

  8. #8
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    try following Me.Requery with Me.Refresh?

  9. #9
    SteveH2508 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Chelsea, London, England
    Posts
    117
    Have you saved the record before returning to the underlying form?

  10. #10
    Rick West is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    90
    The second form allows data to enter directly into the table, I was unaware that it needed to be saved afterwards.

    I thought it was automatically "saved?"

  11. #11
    SteveH2508 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Chelsea, London, England
    Posts
    117
    Quote Originally Posted by Rick West View Post
    The second form allows data to enter directly into the table, I was unaware that it needed to be saved afterwards.

    I thought it was automatically "saved?"
    It would save when you move to another record on the same form - switching between forms (without closing the first one) would not save the record (I don't think).

    Is the textbox bound to 'Description' also called 'Description'? This might cause a problem.

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

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