473,396 Members | 2,011 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,396 software developers and data experts.

Before Insert Event on Subform

I'm having what seems to me to be an odd problem. Perhaps there is some
explanation, but don't know at this point. Basically I have a form that
tracks memberships and donations. The main form tracks the individual and
the subform allows me to add donation amounts or membership fee payments.
It's fairly basic. Well what I want to do is when I enter a new membership
payment it looks to another table. If the person is currently a member, it
does nothing. If the person is an ex-member then it runs an update
statement and changes it to member and if the person has never been a member
it runs an insert statement to add them to the table.

Below is the problem code. The problem comes into play when I'm trying to
evaluate the subform combo box which is what holds the id for what type of
payment it is, whether it be a donation or membership. It runs code based
on its value. It wasn't doing what I wanted so I inserted a debug line to
determine what the combo box was evaluating to. Look at the code below
where there is [problem][/problem]. If I leave it like that I cannot edit
the record in the subform. If I comment out that part I can edit it as much
as my heart desires. WHY?? If I put it into an AfterInsert it allows me to
edit and such but it's pointless because the combobox will evaluate to null
because it's at a new record already. Should I put this in a different
event?

Thanks!

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strSQLInsert As String
Dim strSQLUpdate As String

strSQL = "SELECT idIndividualType FROM tblxrefPatronType"
strSQL = strSQL & " WHERE idIndividual=" &
Forms!frmPatronInfo!txtidIndividual
strSQL = strSQL & " AND idIndividualType IN (1,2)"
Debug.Print "cboidIncomeType: " [problem]&
Forms!frmIncomeType!cboidIncomeType[/problem]
Debug.Print "strSQL1: " & strSQL
Nov 12 '05 #1
2 8533
well the sql code should be:

strSQL = "SELECT idIndividualType FROM tblxrefPatronType"
strSQL = strSQL & " WHERE idIndividual=" &
Forms!frmPatronInfo!txtidIndividual
strSQL = strSQL & " AND idIndividualType IN (1,2)"

Which shows up as such when used:
SELECT idIndividualType FROM tblxrefPatronType WHERE idIndividual=28813 AND
idIndividualType IN (1,2)

That part is all fine and good.

After playing with it a bit I'm thinking it might have something to do with
the fact that there is an autonumber field. Perhaps the insert even occurs
when I enter the first piece of data?

when i have the debug code in there like this:
Debug.Print "cboidIncomeType: " &
Forms!frmPatronInfo!frmIncomeType!cboidIncomeType
Debug.Print "strSQL1: " & strSQL

the debug.prints don't even show up in my immediate window. If I comment
out "& Forms!frmPatronInfo!frmIncomeType!cboidIncomeType" then they both
show up, but of course no value for the first line since it is commented
out. The strSQL line does come up though as it should. This is kind of the
weird situation. Why would it not even show up when it's not commented out?
The thing is is that that first line that is being debugged is the same
field I need to test to determine what do do with the data. So without an
accurate evaluation, it goes nowhere. I could put it on an on exit of one
of the fields, but I wanted it to execute on the before insert, because I
didn't want it inserted and then have someone hit the esc key but leave the
record updated in the other table.

Here's the whole of the code. I haven't put in any execute statements. I
just wanted to make sure it was running the way it should be first. Beware
word wrap.

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strSQLInsert As String
Dim strSQLUpdate As String

strSQL = "SELECT idIndividualType FROM tblxrefPatronType"
strSQL = strSQL & " WHERE idIndividual=" &
Forms!frmPatronInfo!txtidIndividual
strSQL = strSQL & " AND idIndividualType IN (1,2)"

Debug.Print "cboidIncomeType: " &
Forms!frmPatronInfo!frmIncomeType!cboidIncomeType
Debug.Print "strSQL1: " & strSQL

If Forms!frmPatronInfo!frmIncomeType!cboidIncomeType = 3 Then
Set db = CurrentDb()
Set rs = db.OpenRecordset("strSQL")
If rs.RecordCount = 0 Then
strSQLInsert = "INSERT INTO tblxrefPatronType (idIndividual,
idIndividualType)"
strSQLInsert = strSQLInsert & " VALUES (" &
Forms!frmPatronInfo!txtidIndividual & ", 1)"
Debug.Print "strSQLInsert: " & strSQLInsert
Else
Set rs = Nothing
strSQL = "SELECT idIndividualType FROM tblxrefPatronType"
strSQL = strSQL & "WHERE idIndividual=" &
Forms!frmPatronInfo!txtidIndividual
strSQL = strSQL & " AND idIndividualType=2"
Debug.Print "strSQL2: " & strSQL
Set rs = db.OpenRecordset("strSQL")
If rs.RecordCount = 0 Then
Exit Sub
Else
strSQLUpdate = "UPDATE tblxrefPatronType SET idIndividualType=1
WHERE idIndividual="
strSQLUpdate = strSQLUpdate &
Forms!frmPatronInfo!txtidIndividual & " AND idIndividualType=1"
Debug.Print "strSQLUpdate: " & strSQLUpdate
End If
End If
End If


"Bob Quintal" <bq******@generation.net> wrote in message
news:ca******************************@news.teranew s.com...
Your SQL seems to be missing a portion of one of the filter
conditions.

" WHERE idIndividual=" & Forms!frmPatronInfo!txtidIndividual _
& " AND idIndividualType IN (1,2)"
Is okay,

but taking out the debugging code leaves
& Forms!frmIncomeType!cboidIncomeType
which should be something like " And [whatever] = " &
Forms!frmIncomeType!cboidIncomeType

It may be a cut & paste error, but please repost the code.

Bob Q

"Bill" <zi*****@hotmail.com> wrote in
news:vm************@corp.supernews.com:
I'm having what seems to me to be an odd problem. Perhaps
there is some explanation, but don't know at this point.
Basically I have a form that tracks memberships and donations.
The main form tracks the individual and the subform allows me
to add donation amounts or membership fee payments. It's
fairly basic. Well what I want to do is when I enter a new
membership payment it looks to another table. If the person
is currently a member, it does nothing. If the person is an
ex-member then it runs an update statement and changes it to
member and if the person has never been a member it runs an
insert statement to add them to the table.

Below is the problem code. The problem comes into play when
I'm trying to evaluate the subform combo box which is what
holds the id for what type of payment it is, whether it be a
donation or membership. It runs code based on its value. It
wasn't doing what I wanted so I inserted a debug line to
determine what the combo box was evaluating to. Look at the
code below where there is [problem][/problem]. If I leave it
like that I cannot edit the record in the subform. If I
comment out that part I can edit it as much as my heart
desires. WHY?? If I put it into an AfterInsert it allows me
to edit and such but it's pointless because the combobox will
evaluate to null because it's at a new record already. Should
I put this in a different event?

Thanks!

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strSQLInsert As String
Dim strSQLUpdate As String

strSQL = "SELECT idIndividualType FROM tblxrefPatronType"
strSQL = strSQL & " WHERE idIndividual=" &
Forms!frmPatronInfo!txtidIndividual
strSQL = strSQL & " AND idIndividualType IN (1,2)"
Debug.Print "cboidIncomeType: " [problem]&
Forms!frmIncomeType!cboidIncomeType[/problem]
Debug.Print "strSQL1: " & strSQL

Nov 12 '05 #2
Well there are about a dozen other flaws in my code, so I'm going to fix
those first and see if that works. If not I'll probably repost or figure
something else. Why do these things have to be so literal? :)
"Bob Quintal" <bq******@generation.net> wrote in message
news:ca******************************@news.teranew s.com...
Your SQL seems to be missing a portion of one of the filter
conditions.

" WHERE idIndividual=" & Forms!frmPatronInfo!txtidIndividual _
& " AND idIndividualType IN (1,2)"
Is okay,

but taking out the debugging code leaves
& Forms!frmIncomeType!cboidIncomeType
which should be something like " And [whatever] = " &
Forms!frmIncomeType!cboidIncomeType

It may be a cut & paste error, but please repost the code.

Bob Q

"Bill" <zi*****@hotmail.com> wrote in
news:vm************@corp.supernews.com:
I'm having what seems to me to be an odd problem. Perhaps
there is some explanation, but don't know at this point.
Basically I have a form that tracks memberships and donations.
The main form tracks the individual and the subform allows me
to add donation amounts or membership fee payments. It's
fairly basic. Well what I want to do is when I enter a new
membership payment it looks to another table. If the person
is currently a member, it does nothing. If the person is an
ex-member then it runs an update statement and changes it to
member and if the person has never been a member it runs an
insert statement to add them to the table.

Below is the problem code. The problem comes into play when
I'm trying to evaluate the subform combo box which is what
holds the id for what type of payment it is, whether it be a
donation or membership. It runs code based on its value. It
wasn't doing what I wanted so I inserted a debug line to
determine what the combo box was evaluating to. Look at the
code below where there is [problem][/problem]. If I leave it
like that I cannot edit the record in the subform. If I
comment out that part I can edit it as much as my heart
desires. WHY?? If I put it into an AfterInsert it allows me
to edit and such but it's pointless because the combobox will
evaluate to null because it's at a new record already. Should
I put this in a different event?

Thanks!

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strSQLInsert As String
Dim strSQLUpdate As String

strSQL = "SELECT idIndividualType FROM tblxrefPatronType"
strSQL = strSQL & " WHERE idIndividual=" &
Forms!frmPatronInfo!txtidIndividual
strSQL = strSQL & " AND idIndividualType IN (1,2)"
Debug.Print "cboidIncomeType: " [problem]&
Forms!frmIncomeType!cboidIncomeType[/problem]
Debug.Print "strSQL1: " & strSQL

Nov 12 '05 #3

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

Similar topics

4
by: DTB | last post by:
I am having trouble creating an INSTEAD OF trigger in SQL Server to replicate a BEFORE UPDATE trigger from ORACLE. Here is a sample of the ORACLE BEFORE UPDATE trigger: CREATE TRIGGER myTRIGGER ON...
2
by: 73blazer | last post by:
Perhaps my thinking is wrong but this is what I have: 1 table (Tab1) with 1 attribute (Attr1) Attr1 char(16) for bit data ----------------------------------------------- create trigger...
3
by: tomtailor | last post by:
Hello! I have a before insert Trigger and I want to catch if there is a duplicate Key Error. If the Key already exists I'd like to update else insert the row. OK I am at the point I did the...
2
by: lphuong | last post by:
Access 2000 I have a fldCreateDate on frmCustomer(mainform)and also a fldCreateDate on frmCustomerVisit(subform). They are one to many relationship. On the main form, frmCustomer, I have a...
1
by: Jason | last post by:
I have a main form with a sub form. All the fields in the subform are mandatory. I had some code on the main form Before Update Event to check if all the fields in the sub form have data. If not, I...
10
by: Serdge Kooleman | last post by:
i have a query: select id, name from Dictionary field "id" is guid (so not null, and not identity) i show only "name" in the dataGrid how to set new id when i insert a new record? ...
2
by: Serdge Kooleman | last post by:
i have a query: select id, name from Dictionary field "id" is uniqueidentifier (primary key id is not null, and not identity !) i show only "name" in the dataGrid how to set up new id when i...
1
by: gauravupreti | last post by:
Hi All, I have a table with a col. that accepts number. CREATE TABLE A (ID NUMBER NOT NULL) and another table with two columns as shown: CREATE TABLE B (ID NUMBER NOT NULL,
1
by: JB4375 | last post by:
I've created an ASP gridview and made it editable. It displays the information that was entered into a SQL table plus a time stamp and the submitter's user ID. In the event information is edited...
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: 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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.