Hi guys.
I’m not familiar with Ms access VB (or any other for that matter)but learning fast. I have tried various methods to achieve the outcome but all have failed. Background
Front End developed using MS Access Forms which is connected to SQL Server 2005 DB. Allowing users to capture Customer info. Objective
On value input in on the form it needs to make reference to a scorecard (on db), check the input against the scorecard variables and once matched the points associated with the value to be written to another table in db.
I’m hoping I’m not confusing the matter.
Below is one attempt(failed horribly). Don’t have any idea of how to resolve or achieve the outcome. Would appreciate any assistance - Private Sub Form_AfterUpdate()
-
Dim db As DAO.Database
-
Dim SC As DAO.Recordset
-
Dim OutPut As DAO.Recordset
-
Dim Value As Integer
-
-
Set db = CurrentDb()
-
Set SC = db.OpenRecordset("dbo_BBRS_SC", dbOpenSnapshot)
-
Set OutPut = db.OpenRecordset("dbo_Cust_RG_Scr_Values", dbOpenSnapshot, dbSeeChanges)
-
-
Value = Customer!CB_Industry
-
-
If SC.RecordCount = 0 Then Exit Sub
-
-
SC.MoveFirst
-
' loop through each record in the first recordset
-
Do Until SC.RecordCount = 11 Or ctr > 11
-
-
If Value = SC!ID_LKVar Then
-
OutPut.AddNew
-
OutPut![Score] = SC![Score]
-
OutPut.Update
-
-
Else
-
If Value <> SC!ID_LKVar Then
-
OutPut.AddNew
-
OutPut![Score] = 99
-
OutPut.Update
-
End If
-
-
ctr = ctr + 1
-
Loop
-
-
SC.Close
-
OutPut.Close
-
Set SC = Nothing
-
Set OutPut = Nothing
-
Set db = Nothing
-
End If
-
End Sub
Hi Janine,
Thanks for explaining what you're trying to do. It is more or less what I was picturing but it is always good to have clarification.
Before the Do Until loop executes, how many records does SC have in it? I ask this because I believe that your loop is not running.
In addition, as I pointed out yesterday I believe that using the dbOpenSnapshot parameter when opening the OutPut recordset might problematic for you. Try changing dbOpenSnapshot to dbOpenDynamic.
Finally, it looks to me like the placement of the End If on line #39 is not correct. I believe that it needs to be on line #30 just below the End If on line #29. The way it is now, the Do loop terminates before the first If statement inside ends. In fact, I'm surprised that even compiles.
Pat
13 2155 NeoPa 32,556
Expert Mod 16PB
Bonjour Janine (That's all the French I'm allowed due to site regs).
I'm impressed with the way you've laid out the question, so I will certainly try to help. I need you to try to explain in ordinary language though, what it is you are trying to do. Some example data may be helpful in this.
Hi Janine,
As NeoPa points out, a little more information about what you are trying to do (more context) would be useful. In addition, I would ask exactly what is happening to indicate that this is not working. Are you getting a particular error at some point in the code? Looking at your code, I see two things immediately that could cause problems.
The first is that on line #9 you are using the dbOpenSnapshot flag to open the recordset OutPut; however, dbOpenSnapshot is used to open a recordset with fixed records, but you are attempting to change it on lines #20, 21, and 22 by adding a record to it.
The second problem I see is that you are using the RecordCount property in your criteria for the Do Until on line #17. The RecordCount property for a recordset is fixed (unless you are adding or deleting records to it, which is not the case for SC). If SC already has 11 records going into that Do Until comparison, nothing in the loop will execute. You want to loop through SC record by record until you reach the end, so I suspect that you want something more like
Third, you have an End If on line #39 which does not seem to belong there. When you use the one-line version of If...Then as on line #13, the End If is not necessary.
I hope this helps.
Pat
Back to business
I don’t receive any error msg but the code appears not to find a match. Which is not the case. I will attempt to provide some more detail.
Objective: Design, build and implement a Risk Grade Evaluation Tool which will be used by Credit Managers (Banking Industry) indicating Risk level by means of Grading scale for a specific customer business segment based on customer input data (i.e. Industry, Management of Business, Bank account behaviour, Financial information : Audit statements)
Data Structure (portion of it)
Table 1 : Customer Table
Data Captured by Credit Bank Manager in Branch by (Form)
Data fields i.e Date; Customer Number; Industry Type Total Assets est.
Table 2 : Credit Scorecard Parameters
Parameters for above input data and each with their own ranges. i.e. (will just give 2 examples, in total over a 100 are used)
Score Variable Band/Ranges Points
Industry Type : Charity -10
Local Government -20
FinancialTotalAsset: <250 -25
600 5
With all that said. On input the customer record would look something like this
CustNumber IndusType TotAssets
123344 Charity 300
As soon as the user enters the data in the form I want the loop to execute and the points associated with the variable to be stored on different table. i.e.
CustNumber Variable Points
123344 Charity -10
123344 TotAssets 5*
* 300 > than max of 250 and < 600.
Might have elaborated too much but do think its better to provide a picture of whats happening as a whole, to ensure I use the right code in achieving this.
Regards
Janine
Hi Janine,
Thanks for explaining what you're trying to do. It is more or less what I was picturing but it is always good to have clarification.
Before the Do Until loop executes, how many records does SC have in it? I ask this because I believe that your loop is not running.
In addition, as I pointed out yesterday I believe that using the dbOpenSnapshot parameter when opening the OutPut recordset might problematic for you. Try changing dbOpenSnapshot to dbOpenDynamic.
Finally, it looks to me like the placement of the End If on line #39 is not correct. I believe that it needs to be on line #30 just below the End If on line #29. The way it is now, the Do loop terminates before the first If statement inside ends. In fact, I'm surprised that even compiles.
Pat
NeoPa 32,556
Expert Mod 16PB
This is hard to follow Janine. There are various entities which are names with spaces embedded within them. As you don't indicate where the names end it's hard to read you.
Is there maybe a table called [CustNumber Variable Points]? If so, then the details of this table are missing and probably (with my still very hazy understanding of what you're trying to do) quite important.
I have made the changes to the code reflecting "dbOpenDynamic" and moving the "End if" . I now recieve a Run time Error 3001 - Invalid Argument
on the below
Set OutPut = db.OpenRecordset("dbo_Cust_RG_Scr_Values", dbOpenDynamic, dbSeeChanges)
Apologies. the table is to be the "output table" with the fields [CustNumber]; [Variable]; [Points] and the input for it is to be derived from the loop.
Hi Janine,
I see that you indicated the question as being answered, but from your last two posts it seems that is not the case. Are you still getting the 3001 runtime error? If you are, then I will have to look into that.
Pat
Apologies for that. Still getting the error.
Hi All.
Is it possible to called a SQL stored procedure in a form? I orginaly created a sql Stored proc and then later on attempted to replace it with the VB loop. Could I have your opinion on this in terms of which would be best practice ?
Regards
Janine
Hi Janine,
I apologize for being so slow in replying to you. Could you try doing this: - Set OutPut = db.OpenRecordset("dbo_Cust_RG_Scr_Values", , dbSeeChanges)
and seeing if you still get the error?
Pat
Hi Guys
I have amended the code and the below seems to be working but the problem now is by the "Add new" with Error" Object read only". Not the case. Please assist ! - Private Sub BTCustValidation_Click()
-
Dim MyDB As DAO.Database
-
Dim SC As DAO.Recordset
-
Dim Output As DAO.Recordset
-
Dim GRPID As Variant
-
Dim CustNum As Variant
-
Dim SubVarID As Variant
-
Dim Score As Variant
-
Dim ScDate As Double
-
Dim i As Integer
-
-
Set MyDB = CurrentDb()
-
Set SC = MyDB.OpenRecordset("dbo_BBRS_SC")
-
Set Output = MyDB.OpenRecordset("dbo_Cust_RG_Scr_Values", , dbSeeChanges)
-
-
GRPID = SC![GRP_ID]
-
CustNum = Cust_Number
-
SubVarID = SC![Sub_Var_ID]
-
Pionts = SC![Score]
-
ScDate = Date
-
'ORG TYPE'
-
-
For i = 0 To SC![ID_LKVar] = 11#
-
If ID_OrgType = SC![ID_LKVar] Then
-
Output.AddNew
-
Output![GRP_ID] = GRPID
-
Output![PK_Customer] = CustNum
-
Output![Sub_Var_ID] = SubVarID
-
Output![Score] = Pionts
-
Output![Score_Date] = ScDate
-
Output.Update
-
End If
-
Next
-
For i = 0 To SC![ID_LKVar] = 11#
-
If ID_OrgType <> SC![ID_LKVar] Then
-
MsgBox "No Match"
-
End If
-
Next
-
End Sub
Hi Janine,
I haven't worked with SQL Server back-ends very much, but I'm just wondering if there is something in the SQL Server settings for this table that might prevent additions and updates? I cannot see anything in this code that would cause this error.
Pat
Sign in to post your reply or Sign up for a free account.
Similar topics
by: randi_clausen |
last post by:
Using SQL against a DB2 table the 'with' key word is used to
dynamically create a temporary table with an SQL statement that is
retained for the duration of that SQL statement.
What is the...
|
by: hubert.trzewik |
last post by:
Hello,
Is it possible to EXEC stored procedure from a query?
I want to execute stored procedure for every line of SELECT result
table.
I guess it's possible with cursors, but maybe it's...
|
by: aboycalled3 |
last post by:
I'm interested in using the fascinating CSS available at
http://www.moronicbajebus.com/playground/cssplay/reformat-table/
which allows one to present tabular data in a way that's more appealing...
|
by: AFN |
last post by:
Hi. I'm pretty comfortable binding a single recordset result to a
datagrid. But now I have a more unique problem. I have 2 really long
stored procedures that cannot be combined at the SQL...
|
by: gacuna |
last post by:
i want to insert into a temporal table the result of a store procedure.
on sql server the sentence would look like this (already working)
INSERT INTO #SHIPINFO
exec TESTDTA.S59RSH05 @SCBILLTO,...
|
by: RookieDan |
last post by:
Greetings fellow Accessers!
Im new but in Access, but I have some background in different coding.
I have a programme loading customer data into Access belonging to BMW dealers in Europe.
...
|
by: rhepsi |
last post by:
HII all,
im working on postgresql database where i want to copy the data from one table to other table....
when im trying to write the sql query..
ERROR: 42601: syntax error at or near...
|
by: cynderborg |
last post by:
My database is a tool to write an extensive report. I need the ability to pull a canned response from one table into another table if the user wants to adopt the text. I have the form opened that...
|
by: JBurgett |
last post by:
How can I place the results of a dynamically generated select statement into a (#) temp table?
This has me stumped, any help would be greatly appreciated.
(The names used in the following...
|
by: nikolasapl |
last post by:
Is there a command so that instead of displaying the result table (for example the result of the following query) in the grid tab in the SQL Server Analyzer environment, to export it into an .xls...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |