Results 1 to 12 of 12
  1. #1
    Pragmatic is offline Novice
    Windows XP Access 2000
    Join Date
    Sep 2011
    Posts
    9

    Help for correcting Before Update

    Hi all,

    I have the following code on my form "Matter".


    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String

    Set db = CurrentDb
    strSQL = "SELECT count(tblClientMatter.MatterID) as TotRec FROM tblClientMatter WHERE (tblClientMatter.ClientID)= '" & Me.ClientID & "'"

    Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)

    Me!MatterID = "WO-" & rs!TotRec + 1
    Me!MatterID = rs!TotRec + 1



    Set rs = Nothing
    End Sub

    When I click the Add Matter button on my "Client Form" it opens up the matter form, although it displays client id on matter form but does not display/generate the matter id until I save the record is there way it can display the matter id as well on opening?

    Any help suggestion will be highly appreciated.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Is "ClientID" text or a long integer? If it is a long, you don't need delimiters.

    You have two lines setting Me!MatterID. The second line changes the first:

    Code:
    Me!MatterID = "WO-" & rs!TotRec + 1
    Me!MatterID = rs!TotRec + 1
    Try this:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
      Dim db As DAO.Database
      Dim rs As DAO.Recordset
      Dim strSQL As String
    
      Set db = CurrentDb
      strSQL = "SELECT count(tblClientMatter.MatterID) as TotRec"
      strSQL = strSQL & " FROM tblClientMatter"
      strSQL = strSQL & " WHERE (tblClientMatter.ClientID)= '" & Me.ClientID & "'"
    
      Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
    
      Me!MatterID = "WO-" & rs!TotRec + 1
      Me!MatterID = rs!TotRec + 1     ' Why two lines setting Me!MatterID  ???
    
      Me.Repaint  '<<- added
    
      Set rs = Nothing
    End Sub

  3. #3
    Pragmatic is offline Novice
    Windows XP Access 2000
    Join Date
    Sep 2011
    Posts
    9
    Thank you very much for your reply and providing the amended code. I have deleted the extra line but it still does not display/generate the MatterID on opening the "Matter Form" . Is there way when matter form open it show matterid and clientid both. Both "ClientID" and "MatterID" are text fields.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Pragmatic View Post
    Thank you very much for your reply and providing the amended code. I have deleted the extra line but it still does not display/generate the MatterID on opening the "Matter Form" . Is there way when matter form open it show matterid and clientid both. Both "ClientID" and "MatterID" are text fields.
    Would you post your MDB? Do a "Compile and Repair", then zip it.

  5. #5
    Pragmatic is offline Novice
    Windows XP Access 2000
    Join Date
    Sep 2011
    Posts
    9
    Please find attached MDB. Try to open formtwo as stand alone as well please and if you find any error message please advise how to fix it.
    Last edited by Pragmatic; 12-06-2011 at 01:05 PM.

  6. #6
    Pragmatic is offline Novice
    Windows XP Access 2000
    Join Date
    Sep 2011
    Posts
    9
    Quote Originally Posted by ssanfu View Post
    Would you post your MDB? Do a "Compile and Repair", then zip it.
    File is attached please.

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Pragmatic View Post
    File is attached please.
    Had to wait until I got home to look at it - the file is not in A2K format.

    Finally was able to open the MDB. Still trying to understand your MDB.

    Why do you have ClientID as a text type. Most of the time, the PK is an autonumber (long int).

    Still looking at it and trying to get form two to open up with the correct ClientID.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Still looking at it.... hang in there

  9. #9
    Pragmatic is offline Novice
    Windows XP Access 2000
    Join Date
    Sep 2011
    Posts
    9
    Quote Originally Posted by ssanfu View Post
    Still looking at it.... hang in there
    How long do I have to wait. Is this something unusual?

  10. #10
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Pragmatic View Post
    How long do I have to wait. Is this something unusual?
    Well, there is work, the holidays, family obligations and shoveling snow..... I'm still looking at it when I can make time....

  11. #11
    Pragmatic is offline Novice
    Windows XP Access 2000
    Join Date
    Sep 2011
    Posts
    9
    Quote Originally Posted by ssanfu View Post
    Well, there is work, the holidays, family obligations and shoveling snow..... I'm still looking at it when I can make time....
    Hope you will come up with solution....

  12. #12
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Pragmatic View Post
    Hope you will come up with solution....
    Couldn't come up with a solution with your structure, so I changed some field types and links. See if this will work for you.

    Also, I think it would be easier, if not better, to have "frmTwo" as a subform of "frmOne", instead of a pop up form.


    BTW, in the client table, I wouldn't have the fields that end in "_2". This violates normalization rules (but I didn't change it).

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

Similar Threads

  1. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  2. Replies: 1
    Last Post: 08-19-2011, 12:16 PM
  3. correcting typographical errors
    By aflashman in forum Access
    Replies: 1
    Last Post: 07-31-2011, 03:22 PM
  4. Replies: 1
    Last Post: 01-22-2011, 12:23 PM
  5. Update field in table after update on a subform
    By jpkeller55 in forum Queries
    Replies: 3
    Last Post: 09-30-2010, 08:02 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