Adding New Record with Data

G

Guest

My form has a button to allow a user to view or add a record if one does not
exist in an associated table. Coding for the button is shown below. It
works fine if there is a record and "works" to the extent that it creates a
new record, but does not display grantee and address values from the parent
form in the new form. Can someone help me? Thanks Lloyd

frmGrantSumDE is the parent form from table tblGrantSum with DLCDGrant# as
the key field
frmCTrackDE is the child form with the table tblCTrack and DLCDGrant# is
also the name of the key field in this table

DLCDGrant# is a string

If IsNull(DLookup("[DLCDGrant#]", "tblCTrack", "[DLCDGrant#] = '" &
[Forms]![frmGrantSumDE].[DLCDGrant#] & "'")) Then
If MsgBox("No Tracking Record Found. Create a New One?",
vbOKCancel) = vbOK Then
DoCmd.OpenForm "frmCTrackGenInfoDE", acNormal, , , acFormAdd

Forms![frmCTrackGenInfoDE].[DLCDGrant#] =
[Forms]![frmGrantSumDE].[DLCDGrant#]
Forms![frmCTrackGenInfoDE].[Grantee] =
[Forms]![frmGrantSumDE].[Grantee]
Forms![frmCTrackGenInfoDE].[StreetAddress] =
[Forms]![frmGrantSumDE].[StreetAddress]
Forms![frmCTrackGenInfoDE].[City] = [Forms]![frmGrantSumDE].[City]
Forms![frmCTrackGenInfoDE].[Zip] = [Forms]![frmGrantSumDE].[Zip]
Else
MsgBox ("Action Canceled")
End If
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenForm "frmCTrackGenInfoDE", acNormal, , "[DLCDGrant#] = '"
& [Forms]![frmGrantSumDE].[DLCDGrant#] & "'"
End If
 
M

Marshall Barton

Lloyd said:
My form has a button to allow a user to view or add a record if one does not
exist in an associated table. Coding for the button is shown below. It
works fine if there is a record and "works" to the extent that it creates a
new record, but does not display grantee and address values from the parent
form in the new form. Can someone help me? Thanks Lloyd

frmGrantSumDE is the parent form from table tblGrantSum with DLCDGrant# as
the key field
frmCTrackDE is the child form with the table tblCTrack and DLCDGrant# is
also the name of the key field in this table

DLCDGrant# is a string

If IsNull(DLookup("[DLCDGrant#]", "tblCTrack", "[DLCDGrant#] = '" &
[Forms]![frmGrantSumDE].[DLCDGrant#] & "'")) Then
If MsgBox("No Tracking Record Found. Create a New One?",
vbOKCancel) = vbOK Then
DoCmd.OpenForm "frmCTrackGenInfoDE", acNormal, , , acFormAdd

Forms![frmCTrackGenInfoDE].[DLCDGrant#] =
[Forms]![frmGrantSumDE].[DLCDGrant#]
Forms![frmCTrackGenInfoDE].[Grantee] =
[Forms]![frmGrantSumDE].[Grantee]
Forms![frmCTrackGenInfoDE].[StreetAddress] =
[Forms]![frmGrantSumDE].[StreetAddress]
Forms![frmCTrackGenInfoDE].[City] = [Forms]![frmGrantSumDE].[City]
Forms![frmCTrackGenInfoDE].[Zip] = [Forms]![frmGrantSumDE].[Zip]
Else
MsgBox ("Action Canceled")
End If
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenForm "frmCTrackGenInfoDE", acNormal, , "[DLCDGrant#] = '"
& [Forms]![frmGrantSumDE].[DLCDGrant#] & "'"
End If


Not sure what your problem is. I got something a lot like
this to work for me:

If IsNull(DLookup("[DLCDGrant#]", "tblCTrack", _
"[DLCDGrant#] = '" & Me.[DLCDGrant#] & "'")) Then
If MsgBox("No Tracking Record Found. Create a New One?",
vbOKCancel) = vbOK Then
DoCmd.OpenForm "frmCTrackGenInfoDE", acNormal, , , _
acFormAdd

With Forms!frmCTrackGenInfoDE
.[DLCDGrant#]=Me.[DLCDGrant#]
.Grantee=Me.Grantee
.StreetAddress=Me.StreetAddress
.City=Me.City
.Zip=Me.Zip
End With
Else
MsgBox "Action Canceled"
End If
Else
If Me.Dirty Then Me.Dirty = False
DoCmd.OpenForm "frmCTrackGenInfoDE", acNormal, , _
"[DLCDGrant#] = '" &Me.[DLCDGrant#] & "'"
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top