473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

GTRR; If no Related Record, Create New In 2nd Form

I've been trying to do something for about 3 days – I get close, but
not 100%.
I am trying to:

Open frmRevisionHistory from a button on frmFeeInput.

If there is NO RELATED RECORD, then I need to create one in
frmRevisionHistory, and pass the PK (PK_Fees) on frmFeeInput to
FK_Fees on the 2nd form.

If there IS (OR ARE) RELATED RECORDS, then go to them on
frmRevisionHistory.

Right now, I am getting error message 2046 "The command or action
RecordsGoToNew isn't available now."

Here's the code:

Private Sub butGoToHistory_Click()

On Error GoTo Error_Handler:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmRevisionHistory"

stLinkCriteria = "[FK_Fees]=" & Me![PK_Fees]
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria

If RecordsetCount = 0 Then
MsgBox "No history records. Will create one now", vbOKOnly,
"Create Record"
DoCmd.RunCommand acCmdRecordsGoToNew
'DoCmd.GoToRecord , , acNewRec 'Access Wizard code
Dim sSQL As String
DoCmd.SetWarnings False

sSQL = "INSERT INTO tblRevisionHistory ( FK_Fees)" & _
" SELECT Forms!frmFeeInput!PK_Fees AS intCode" & _
" FROM tblFees;"

DoCmd.RunSQL (sSQL)

DoCmd.SetWarnings True
frmRevisionHistory.Requery

Else
stLinkCriteria = "[FK_Fees]=" & Me![PK_Fees]
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria
MsgBox "RELATED RECORD!"
frmRevisionHistory.Requery

End If

Exit Sub

Error_Handler:
MsgBox Err.Description & " " & Err.Number
Nov 13 '05 #1
4 4029
Amy, I get the feeling that there are some conceptual issues here.

First forms don't hold records. They are normally *bound* to a
RecordSource - sometimes a table but usually a query. I think is
notion is screwing up your approach to the problem.

Try it like this:

1.) Test the existence of the record with a Dlookup function.

2.) If it doesn't exist create it *before* you attempt to open the
other form

This ought to work...
============
Private Sub butGoToHistory_Click()
Dim stDocName As String

stDocName = "frmRevisionHistory"

'Lets see if the record exists
If IsNull(DLookup("FK_Fees", "tblRevisionHistory", _
"FK_Fees=" & Me.PK_Fees)) Then
'It doesn't so insert the record
sSQL = "INSERT INTO tblRevisionHistory (FK_Fees) " _
& "VALUES (" & Me.PK_Fees & ");"
CurrentDb.Execute sSQL, dbFailOnError
Else
'Record exists just open the form with WHERE Condition
DoCmd.OpenForm stDocName, , , "FK_Fees=" & Me.PK_Fees
End If

End Sub
=======================

- Jim
On 13 Jul 2004 15:33:39 -0700, am*******@verizon.net (amywolfie)
wrote:
I've been trying to do something for about 3 days – I get close, but
not 100%.
I am trying to:

Open frmRevisionHistory from a button on frmFeeInput.

If there is NO RELATED RECORD, then I need to create one in
frmRevisionHistory, and pass the PK (PK_Fees) on frmFeeInput to
FK_Fees on the 2nd form.

If there IS (OR ARE) RELATED RECORDS, then go to them on
frmRevisionHistory.

Right now, I am getting error message 2046 "The command or action
RecordsGoToNew isn't available now."

Here's the code:

Private Sub butGoToHistory_Click()

On Error GoTo Error_Handler:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmRevisionHistory"

stLinkCriteria = "[FK_Fees]=" & Me![PK_Fees]
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria

If RecordsetCount = 0 Then
MsgBox "No history records. Will create one now", vbOKOnly,
"Create Record"
DoCmd.RunCommand acCmdRecordsGoToNew
'DoCmd.GoToRecord , , acNewRec 'Access Wizard code
Dim sSQL As String
DoCmd.SetWarnings False

sSQL = "INSERT INTO tblRevisionHistory ( FK_Fees)" & _
" SELECT Forms!frmFeeInput!PK_Fees AS intCode" & _
" FROM tblFees;"

DoCmd.RunSQL (sSQL)

DoCmd.SetWarnings True
frmRevisionHistory.Requery

Else
stLinkCriteria = "[FK_Fees]=" & Me![PK_Fees]
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria
MsgBox "RELATED RECORD!"
frmRevisionHistory.Requery

End If

Exit Sub

Error_Handler:
MsgBox Err.Description & " " & Err.Number


Nov 13 '05 #2
Taking another look at this; the Else isn't needed but the open form
is. So...

Private Sub butGoToHistory_Click()
Dim stDocName As String

stDocName = "frmRevisionHistory"

'Lets see if the record exists
If IsNull(DLookup("FK_Fees", "tblRevisionHistory", _
"FK_Fees=" & Me.PK_Fees)) Then
'It doesn't so insert the record
sSQL = "INSERT INTO tblRevisionHistory (FK_Fees) " _
& "VALUES (" & Me.PK_Fees & ");"
CurrentDb.Execute sSQL, dbFailOnError
End If
'Now open the form with WHERE Condition
DoCmd.OpenForm stDocName, , , "FK_Fees=" & Me.PK_Fees

End Sub

- Jim

On Tue, 13 Jul 2004 23:56:16 GMT, "Jim Allensworth"
<ji****@datacentricsolutions.com> wrote:
Amy, I get the feeling that there are some conceptual issues here.

First forms don't hold records. They are normally *bound* to a
RecordSource - sometimes a table but usually a query. I think is
notion is screwing up your approach to the problem.

Try it like this:

1.) Test the existence of the record with a Dlookup function.

2.) If it doesn't exist create it *before* you attempt to open the
other form

This ought to work...
============
Private Sub butGoToHistory_Click()
Dim stDocName As String

stDocName = "frmRevisionHistory"

'Lets see if the record exists
If IsNull(DLookup("FK_Fees", "tblRevisionHistory", _
"FK_Fees=" & Me.PK_Fees)) Then
'It doesn't so insert the record
sSQL = "INSERT INTO tblRevisionHistory (FK_Fees) " _
& "VALUES (" & Me.PK_Fees & ");"
CurrentDb.Execute sSQL, dbFailOnError
Else
'Record exists just open the form with WHERE Condition
DoCmd.OpenForm stDocName, , , "FK_Fees=" & Me.PK_Fees
End If

End Sub
=======================

- Jim
On 13 Jul 2004 15:33:39 -0700, am*******@verizon.net (amywolfie)
wrote:
I've been trying to do something for about 3 days – I get close, but
not 100%.
I am trying to:

Open frmRevisionHistory from a button on frmFeeInput.

If there is NO RELATED RECORD, then I need to create one in
frmRevisionHistory, and pass the PK (PK_Fees) on frmFeeInput to
FK_Fees on the 2nd form.

If there IS (OR ARE) RELATED RECORDS, then go to them on
frmRevisionHistory.

Right now, I am getting error message 2046 "The command or action
RecordsGoToNew isn't available now."

Here's the code:

Private Sub butGoToHistory_Click()

On Error GoTo Error_Handler:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmRevisionHistory"

stLinkCriteria = "[FK_Fees]=" & Me![PK_Fees]
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria

If RecordsetCount = 0 Then
MsgBox "No history records. Will create one now", vbOKOnly,
"Create Record"
DoCmd.RunCommand acCmdRecordsGoToNew
'DoCmd.GoToRecord , , acNewRec 'Access Wizard code
Dim sSQL As String
DoCmd.SetWarnings False

sSQL = "INSERT INTO tblRevisionHistory ( FK_Fees)" & _
" SELECT Forms!frmFeeInput!PK_Fees AS intCode" & _
" FROM tblFees;"

DoCmd.RunSQL (sSQL)

DoCmd.SetWarnings True
frmRevisionHistory.Requery

Else
stLinkCriteria = "[FK_Fees]=" & Me![PK_Fees]
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria
MsgBox "RELATED RECORD!"
frmRevisionHistory.Requery

End If

Exit Sub

Error_Handler:
MsgBox Err.Description & " " & Err.Number


Nov 13 '05 #3
Jim:

You rule! This worked like a charm! Thank you very much. It's hard
to move from the mindset required for FileMaker to Access...

Thanks again,
amy
==

Ji****@datacentricsolutions.com (Jim Allensworth) wrote in message news:<40***************@netnews.comcast.net>...
Taking another look at this; the Else isn't needed but the open form
is. So...

Private Sub butGoToHistory_Click()
Dim stDocName As String

stDocName = "frmRevisionHistory"

'Lets see if the record exists
If IsNull(DLookup("FK_Fees", "tblRevisionHistory", _
"FK_Fees=" & Me.PK_Fees)) Then
'It doesn't so insert the record
sSQL = "INSERT INTO tblRevisionHistory (FK_Fees) " _
& "VALUES (" & Me.PK_Fees & ");"
CurrentDb.Execute sSQL, dbFailOnError
End If
'Now open the form with WHERE Condition
DoCmd.OpenForm stDocName, , , "FK_Fees=" & Me.PK_Fees

End Sub

- Jim

On Tue, 13 Jul 2004 23:56:16 GMT, "Jim Allensworth"
<ji****@datacentricsolutions.com> wrote:
Amy, I get the feeling that there are some conceptual issues here.

First forms don't hold records. They are normally *bound* to a
RecordSource - sometimes a table but usually a query. I think is
notion is screwing up your approach to the problem.

Try it like this:

1.) Test the existence of the record with a Dlookup function.

2.) If it doesn't exist create it *before* you attempt to open the
other form

This ought to work...
============
Private Sub butGoToHistory_Click()
Dim stDocName As String

stDocName = "frmRevisionHistory"

'Lets see if the record exists
If IsNull(DLookup("FK_Fees", "tblRevisionHistory", _
"FK_Fees=" & Me.PK_Fees)) Then
'It doesn't so insert the record
sSQL = "INSERT INTO tblRevisionHistory (FK_Fees) " _
& "VALUES (" & Me.PK_Fees & ");"
CurrentDb.Execute sSQL, dbFailOnError
Else
'Record exists just open the form with WHERE Condition
DoCmd.OpenForm stDocName, , , "FK_Fees=" & Me.PK_Fees
End If

End Sub
=======================

- Jim
On 13 Jul 2004 15:33:39 -0700, am*******@verizon.net (amywolfie)
wrote:
I've been trying to do something for about 3 days ? I get close, but
not 100%.
I am trying to:

Open frmRevisionHistory from a button on frmFeeInput.

If there is NO RELATED RECORD, then I need to create one in
frmRevisionHistory, and pass the PK (PK_Fees) on frmFeeInput to
FK_Fees on the 2nd form.

If there IS (OR ARE) RELATED RECORDS, then go to them on
frmRevisionHistory.

Right now, I am getting error message 2046 "The command or action
RecordsGoToNew isn't available now."

Here's the code:

Private Sub butGoToHistory_Click()

On Error GoTo Error_Handler:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmRevisionHistory"

stLinkCriteria = "[FK_Fees]=" & Me![PK_Fees]
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria

If RecordsetCount = 0 Then
MsgBox "No history records. Will create one now", vbOKOnly,
"Create Record"
DoCmd.RunCommand acCmdRecordsGoToNew
'DoCmd.GoToRecord , , acNewRec 'Access Wizard code
Dim sSQL As String
DoCmd.SetWarnings False

sSQL = "INSERT INTO tblRevisionHistory ( FK_Fees)" & _
" SELECT Forms!frmFeeInput!PK_Fees AS intCode" & _
" FROM tblFees;"

DoCmd.RunSQL (sSQL)

DoCmd.SetWarnings True
frmRevisionHistory.Requery

Else
stLinkCriteria = "[FK_Fees]=" & Me![PK_Fees]
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria
MsgBox "RELATED RECORD!"
frmRevisionHistory.Requery

End If

Exit Sub

Error_Handler:
MsgBox Err.Description & " " & Err.Number

Nov 13 '05 #4
On 14 Jul 2004 09:27:51 -0700, am*******@verizon.net (amywolfie)
wrote:
Jim:

You rule! This worked like a charm! Thank you very much. It's hard
to move from the mindset required for FileMaker to Access...

Thanks again,
amy
==


Your'e welcome. And right it's a mindset thing. I can only imagine how
it might be for me working in the other direction.

- Jim
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: elvin | last post by:
Okay - apologize in advance for the length, but I want to make sure all you knowledgeable and helpful people have all the details you need to hopefully point my newbie rear in the right direction....
2
by: Colm O'Hagan | last post by:
Hi there, I having a problem with a database I'm setting up, I would be delighted if someone out there could help. The database I'm setting up is a task register datebase, it will be used to...
0
by: amywolfie | last post by:
I've been trying to do something for about 3 days – I get close, but not 100%. I am trying to: Open frmRevisionHistory from a button on frmFeeInput. If there is NO RELATED RECORD, then I...
6
by: skgolden | last post by:
My husband and I own a small temporary labor company and deal with 4 major clients (A,B,C & D), each of which has about 2 dozen units in our tristate area that we deal with (ie, Company A, units...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
3
by: Simone | last post by:
Hi All, I have a Find Record button setup in most of my forms in order to find a specific customer's details. I have just noticed today though that this search will only find the customer if it...
12
by: swingingming | last post by:
Hi, in the NorthWind sample database, when clicking on the next navigation button on the new order record with nothing on the subform (order details), we got an order with nothing ordered. How can...
2
by: dBNovice | last post by:
Hi all! I have 3 separate forms: Tasks, Subtasks, and Elements. All 3 is related by TaskId and Subtasks and Elements are related by SubtaskID. In the DB after I add a task, I want to be able to...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.