473,472 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 4034
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.