I've got a form with property data form (frmPropertyHistory). On this form I have button to add a new property which opens an unbound, modal form (frmAddNewProperty). On this form new I have two fields with data to enter in a table (txtNewOwner and txtNewProperty). This is the code:
This works OK as the data is inserted in the tables, but in order for the original form (frmPropertyHistory) to show the new property, I need to close it and reload it. Why? Is there a more elegant way to refresh/requery this form to show the new data?
Without these two last lines of code, it is interesting to see that the combobox that I use on this form to select properties shows the new property name, but when I select it the new record does load.
Thanks
mafhobb
Code:
Private Sub cmdAdd_Click()
'Verify that there is data in both fields
Me.txtNewOwner.SetFocus
If Me.txtNewOwner.Text = "" Or IsNull(Me.txtNewOwner.Text) Then
MsgBox "Please add a new owner"
Exit Sub
End If
Me.txtNewProperty.SetFocus
If Me.txtNewProperty.Text = "" Or IsNull(Me.txtNewProperty.Text) Then
MsgBox "Please add a new property"
Exit Sub
End If
' Insert data into tables so a new property is added
Dim dbs As Database
Dim NewOwner As String
Dim NewProperty As String
Me.txtNewOwner.SetFocus
NewOwner = Me.txtNewOwner.Text
Me.txtNewProperty.SetFocus
NewProperty = Me.txtNewProperty.Text
CurrentDb.Execute "INSERT INTO [tblOwners] (OwnerName)" & _
" VALUES ('" & NewOwner & "')"
CurrentDb.Execute "INSERT INTO [tblProperties] (PropertyName, OwnerName)" & _
" VALUES ('" & NewProperty & "', '" & NewOwner & "')"
DoCmd.Close
DoCmd.Close acForm, "frmPropertyHistory", acSaveYes
DoCmd.OpenForm "frmPropertyHistory"
End Sub
Without these two last lines of code, it is interesting to see that the combobox that I use on this form to select properties shows the new property name, but when I select it the new record does load.
Thanks
mafhobb