Results 1 to 8 of 8
  1. #1
    l3111 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    38

    Opening Saved data in form in Edit mode

    I have two forms based on two tables:



    tblReferralsDischarges ---- frmReferralsDischarges
    tblOtherServices ---- frmOtherServices

    Customers are entered in the frmReferralsDischarges, assigned a Referral Autonumber, and all thier information including their RAISE Number (a unique identifer to that person) and all the information relating to thier referral. There is a command button which opens frmOtherServices. OpenArgs is used to copy across the ReferralAutonumber and the RAISE Number. Then other services that that customer has been referred to can be entered.

    This is where my problem occurs.

    Whilst i can enter data, and it saves under the correct person, if i leave the form (frmOtherServices) and go back in to it at a later date to enter more information relating that referral, it opens a blank form. No data is kept and a new entry occurs within the table.

    How do I fix this???



    l3111,Manchester, UK

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Show the code for opening form to existing record. Is the form set to AllowEdits?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    l3111 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    38
    this code?
    Private Sub Form_Load()
    Dim strOpenArgs() As String
    If Not IsNull(Me.OpenArgs) Then
    strOpenArgs = Split(Me.OpenArgs, ";")
    Me.RAISENumber = strOpenArgs(0)
    Me.ReferralAutonumber = strOpenArgs(1)
    Else
    Me.RAISENumber = 0
    Me.ReferralAutonumber = 0
    End If


    and allow edits is set to yes


    End Sub

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not what I was expecting but relevant anyway. That code would replace values of existing record, even if no OpenArgs passed. Why the Else?

    I was expecting, perhaps in a button click event of the calling form, something more like:

    DoCmd.OpenForm "formname", , , "CustomerID=" & Me!ID
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    l3111 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    38
    Else - as a backup if no RAISE Number is entered (but 95% of the time one will be)

    And yes the link criteria is what I think I need to use ONCE the data has been saved, but if a new referral is added, I need the RAISE number to be passed over (hence the use of OpenArgs) I need these two to work together...but I'm unsure if this is possible :/

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Yes, should be able to make work. Because of the Else conditional in the Load the RaiseNumber and ReferralAutonumber would be overwritten with 0 values. So provide OpenArgs even when opening to existing record.
    DoCmd.OpenForm "formname", , , "CustomerID=" & Me!ID, , ,""

    Then modify the Load event code:
    If Len(Me.OpenArgs) > 0 Then
    strOpenArgs = Split(Me.OpenArgs, ";")
    Me.RAISENumber = strOpenArgs(0)
    Me.ReferralAutonumber = strOpenArgs(1)
    ElseIf IsNull(Me.OpenArgs) Then
    Me.RAISENumber = 0
    Me.ReferralAutonumber = 0
    End If

    Or don't provide empty string as OpenArgs then:
    If Not IsNull(Me.OpenArgs) Then
    ...
    ElseIf
    Me.RAISENumber = Nz(Me!RAISENumber,0)
    Me.ReferralAutonumber = Nz(Me!ReferralAutonumber,0)
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    l3111 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    38
    Hi June7

    Firstly, thanks for your help. Secondly, I apologise for my VB ignorance, learning very much on the job here!!

    At present, I have this code behind my command button:

    Private Sub cmdOtherServices_Click()
    On Error GoTo Err_cmdOtherServices_Click


    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmOtherServices"
    stLinkCriteria = "[ReferralAutonumber]=" & Me![ReferralAutonumber]
    DoCmd.OpenForm stDocName, , , , , , Me.[RAISE Number] & ";" & Me.ReferralAutonumber



    Exit_cmdOtherServices_Click:
    Exit Sub
    Err_cmdOtherServices_Click:
    MsgBox Err.Description
    Resume Exit_cmdOtherServices_Click

    End Sub

    From your post, are you suggesting I remove all this code and insert that line, or place that line within my code?

    Also, i'm unsure of what you mean by "empty strings" in relation to OpenArgs. What does the Nz mean in the second OpenArgs code??

    Many Thanks

    l3111, Manchester, UK

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I am suggesting you place the line in whatever event opens the form to an existing record. It could be a button 'Open Existing Record' Click event or the AfterUpdate event of an unbound combobox where user selects from droplist of existing customers.

    What are the settings for form properties of: DataEntry, AllowEdits, AllowDeletion, AllowEdits.

    The OpenForm code you currently have does not specify either a new or an existing record. Makes me suspect the form is set up only for new record entry. The properties I listed can limit that by their settings. I would set all except DataEntry to Yes then control what state the form opens by use of OpenForm arguments. (If the properties are all set as I suggest and the form RecordSource is unfiltered then it is always opening to existing record.) So in addition to the event that opens to existing record, code in the event to open new record would be:

    DoCmd.OpenForm "form name", , , , acFormAdd, , Me.[RAISE Number] & ";" & Me.ReferralAutonumber

    An empty string is string data of zero length. A null has nothing. Nz is a function to handle null, it provides an alternate value if the variable (such as a textbox) is null.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 01-14-2011, 10:37 AM
  2. Replies: 0
    Last Post: 06-14-2010, 09:41 AM
  3. Replies: 9
    Last Post: 02-19-2010, 12:07 PM
  4. Replies: 7
    Last Post: 12-24-2009, 08:44 PM
  5. Opening Form in Data Entry Mode Problem
    By alsoto in forum Forms
    Replies: 1
    Last Post: 05-28-2009, 07:45 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