PeregrinTook
Registered User.
- Local time
 - Today, 03:08
 
- Joined
 - Aug 1, 2006
 
- Messages
 - 15
 
Evening all,
Having a bit of a problem with a 'cattery management' database I'm working on, wonder if anyone can suggest anything pls...
From the main form "OwnersAndCats" (Main table from 'tblOwners', subform from 'tblCats') the user can either add a new cat for a current owner or a new owner, both of which are popup forms.
If the user adds a new cat to the currently selected owner, when they save and close the data entry popup form 'AddCat' I want the main form "OwnersAndCats" to be updated with the newly added cat and the form to display the owner which has just had the cat added.
If the user adds a new owner, they can either just add an owner and return to the main form or go on to add cats before returning - but either way I want the same thing to happen, ie the end result is having the main form "OwnersAndCats" displayed at the record which has just been added.
The problem I'm having is like this. The code below seems to work perfectly if I add a new cat to one of the six sample owners I imported to the table 'tblOwners' from an excel spreadsheet, but when I try it on newly created owners I get the message 'You cant go to the specified record'. Even after I get this message when trying it on one of the newly created owners I can go back to adding a cat for one of the original six and it works perfectly.
I also get the same message when I try to create a new owner then close out back to the main form. I'm sure it must be a very simple thing I'm doing wrong so if anyone can spot the mistake I'd really appreciate it! In fact if anyone can even suggest an easier way to achieve what I'm trying to do that'd also be very useful - the code's untidy I know, but I am very much a novice still - the only reason I've used the method below to show an updated form is because I'm led to believe you can't just close a popup form and simply refresh the main one behind it...
Here's the code for btnACSave on form "AddCat"
	
	
	
		
And here's the code for btnAOSave on form "AddOwner"
	
	
	
		
And finally my global variables:
	
	
	
		
Many thanks for taking the time to help!
 Having a bit of a problem with a 'cattery management' database I'm working on, wonder if anyone can suggest anything pls...
From the main form "OwnersAndCats" (Main table from 'tblOwners', subform from 'tblCats') the user can either add a new cat for a current owner or a new owner, both of which are popup forms.
If the user adds a new cat to the currently selected owner, when they save and close the data entry popup form 'AddCat' I want the main form "OwnersAndCats" to be updated with the newly added cat and the form to display the owner which has just had the cat added.
If the user adds a new owner, they can either just add an owner and return to the main form or go on to add cats before returning - but either way I want the same thing to happen, ie the end result is having the main form "OwnersAndCats" displayed at the record which has just been added.
The problem I'm having is like this. The code below seems to work perfectly if I add a new cat to one of the six sample owners I imported to the table 'tblOwners' from an excel spreadsheet, but when I try it on newly created owners I get the message 'You cant go to the specified record'. Even after I get this message when trying it on one of the newly created owners I can go back to adding a cat for one of the original six and it works perfectly.
I also get the same message when I try to create a new owner then close out back to the main form. I'm sure it must be a very simple thing I'm doing wrong so if anyone can spot the mistake I'd really appreciate it! In fact if anyone can even suggest an easier way to achieve what I'm trying to do that'd also be very useful - the code's untidy I know, but I am very much a novice still - the only reason I've used the method below to show an updated form is because I'm led to believe you can't just close a popup form and simply refresh the main one behind it...
Here's the code for btnACSave on form "AddCat"
		Code:
	
	
	Private Sub btnACSave_Click()
    Dim stDocName As String
    Dim stDocName2 As String
    stDocName = "OwnersAndCats"
    stDocName2 = "AddCat"
On Error GoTo Err_btnACSave_Click
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    
    YesNo = MsgBox("This cat has been added successfully, do you want to add another cat for this owner?", vbYesNo + vbQuestion, "Add More Cats?")
      Select Case YesNo
      Case vbYes
        DoCmd.GoToRecord , , acNext
      Case vbNo
        Select Case stFormName
        Case "OwnersAndCats"
            DoCmd.Close acForm, stDocName2
            DoCmd.Close acForm, stDocName
            DoCmd.OpenForm stDocName
            DoCmd.GoToRecord acDataForm, stDocName, acGoTo, stLinkOwnerID
        Case Else
            Call Init_Globals(Me, OwnerID)
            DoCmd.Close
        End Select
      End Select
    
Exit_btnACSave_Click:
    Exit Sub
Err_btnACSave_Click:
    MsgBox Err.Description
    Resume Exit_btnACSave_Click
    
End Sub
	And here's the code for btnAOSave on form "AddOwner"
		Code:
	
	
	Private Sub btnAOSave_Click()
    
    Dim stDocName As String
    Dim stDocName2 As String
    Dim stDocName3 As String
    Dim stLinkCriteria As String
On Error GoTo Err_btnAOSave_Click
    stDocName = "OwnersAndCats"
    stDocName2 = "AddOwner"
    stDocName3 = "AddCat"
    
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    YesNo = MsgBox("The owner has been added successfully, do you want to add a cat(s) now for this owner?", vbYesNo + vbQuestion, "Add Cats?")
    Select Case YesNo
        Case vbYes
          Call Init_Globals(Me, OwnerID)
          stLinkCriteria = "[OwnerID]=" & stLinkOwnerID
          DoCmd.OpenForm stDocName3, , , stLinkCriteria
        Case vbNo
          YesNo = MsgBox("Do you want to add another owner?", vbYesNo + vbQuestion, "Add More Owners?")
            Select Case YesNo
            Case vbYes
              DoCmd.GoToRecord , , acNext
            Case vbNo
              Select Case stFormName
              Case "OwnersAndCats", "AddCat"
                  DoCmd.Close acForm, stDocName2
                  DoCmd.Close acForm, stDocName
                  DoCmd.OpenForm stDocName
                  DoCmd.GoToRecord acDataForm, stDocName, acGoTo, stLinkOwnerID
              Case Else
                  DoCmd.Close
              End Select
        End Select
    End Select
Exit_btnAOSave_Click:
    Exit Sub
Err_btnAOSave_Click:
    MsgBox Err.Description
    Resume Exit_btnAOSave_Click
    
End Sub
	And finally my global variables:
		Code:
	
	
	Option Compare Database
Global stLinkOwnerID As Integer
Global stFormName As String
Option Explicit
Public Sub Init_Globals(rfrm As Form, OwnerID As Integer)
    stLinkOwnerID = rfrm.OwnerID
    stFormName = rfrm.Name
End Sub
	Many thanks for taking the time to help!