What is wrong with this code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am calling up another data entry form from my current form and that seems
to work but every time I try keying data in the data entry form it makes a
new record instead of linking to the main form. Please Help Me!

Button On Main Form

Private Sub Command206_Click()
If Not IsNull(Me.Last) Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "RuralHome"
Forms![RuralHome]![temp] = Me.Last
DoCmd.OpenForm "RuralHome"
DoCmd.Requery
End If
End Sub

Record Source
SELECT * FROM RHS WHERE [Last]=("&Forms!FormRuralHome[Last]&");

Thank You

Mallory
 
The first thing that's obviously wrong is that you open the RuralHome
form twice.

I am calling up another data entry form from my current form and that seems
to work but every time I try keying data in the data entry form it makes a
new record instead of linking to the main form. Please Help Me!

Button On Main Form

Private Sub Command206_Click()
If Not IsNull(Me.Last) Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "RuralHome"
Forms![RuralHome]![temp] = Me.Last
DoCmd.OpenForm "RuralHome"
DoCmd.Requery
End If
End Sub

Record Source
SELECT * FROM RHS WHERE [Last]=("&Forms!FormRuralHome[Last]&");

Thank You

Mallory
 
Are you trying to sync the the Rural Home form record to the calling form
record?

If yes, try this if the field [Last] is a text field:

Private Sub Command206_Click()
If Not IsNull(Me.Last) Then
DoCmd.OpenForm "RuralHome", , , "[Last] '= " & [Last] & "'"
DoCmd.OpenForm "RuralHome"
End If
End Sub

If last is a number use this change the third line to:
DoCmd.OpenForm "RuralHome", , , "[Last] = " & [Last]


God Bless,

Mark A. Sam
 
Back
Top