I have been trying to figure this out for a couple weeks and after reading every post in the forum about the subject I have not found anything that works.
I have two tables;
1) has company numbers/cost centers, hierarchys, markets, and regions
2) the main table to which the information goes to.
I know it has something to do with the cost centers beacuse when I debug, everything else works.
My code is as follows; - Private Sub Co_Cost_Center_AfterUpdate()
-
Me.Hierarchy = DLookup("Hierarchy", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'")
-
Me.Market = DLookup("Market", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'")
-
Me.Region = DLookup("Region", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'")
-
End Sub
When I go to tab out of the Co/cost ctr field it gives me the runtime error 2001 you canceled the previous operation.
Any ideas?
20 19968
I take it the co_cost_ctr is alphanumeric and not just numeric
Another thing, DLOOKUP returns null if no records found. What are the types for the 3 fields you are setting? U could wrap DLOOKUP with NZ and supply a default value
eg
Me.Region = NZ(DLookup("Region", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'"),"")
One more thing to try, your DB is not corrupt right. Ive heard before a corrupt db causing that error. Rare but has happened, so u could try a compact/repair or a decompile (always backup db first, stick with original if it makes no difference)
I take it the co_cost_ctr is alphanumeric and not just numeric
Another thing, DLOOKUP returns null if no records found. What are the types for the 3 fields you are setting? U could wrap DLOOKUP with NZ and supply a default value
eg
Me.Region = NZ(DLookup("Region", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'"),"")
One more thing to try, your DB is not corrupt right. Ive heard before a corrupt db causing that error. Rare but has happened, so u could try a compact/repair or a decompile (always backup db first, stick with original if it makes no difference)
The co/cost center is alphanumeric. Im not sure I understand what you ean by the types for the three fields I am setting. They are all text fields if that is what you mean.
I tried compacting/repairing the database and it did nothing.
I will try the NZ thing but Im not sure what that will do.
I know it has something to do with the Co/cost ctr because that is where it gets stuck. Im fairly new with Access so I appologize for not understanding some of the things you are saying.
No problems
Now when u perform a DLOOKUP, it is one fetch, if you are doing multiple DLOOKUPS using the same criteria, its slow (though u may not notice) so its better to use a recordset
eg -
Private Sub Co_Cost_Center_AfterUpdate()
-
Dim rs as DAO.Recordset
-
-
'Check if cost center specified
-
if IsNull(Me.Co_Cost_Center) = True then
-
msgbox "No Cost Center Found"
-
else
-
set rs=currentdb.openrecordset("SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.Co_Cost_Center & "'"
-
-
'Check if cost center exists in db
-
if rs.eof = true then
-
msgbox "No records found for cost center " & Me.Co_Cost_Center
-
else
-
Me.Hierarchy = rs!Hierarchy
-
Me.Market = rs!Market
-
Me.Region = rs!Region
-
end if
-
-
rs.close
-
set rs=nothing
-
End Sub
-
Does the above code make any sense to you?
If it complains about
DAO.Recordset
ensure u have added Microsoft DAO Object Library v3.6
u do this by going into Tools/References (from vba window)
If it complains about
DAO.Recordset
ensure u have added Microsoft DAO Object Library v3.6
u do this by going into Tools/References (from vba window)
I put that code in but it gave me a syntax error on this line - set rs=currentdb.openrecordset("SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.Co_Cost_Center & "'"
Am I supposed to change something?
Sorry, forgot closing round bracket
air code typing
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.Co_Cost_Center & "'")
Sorry, forgot closing round bracket
air code typing
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.Co_Cost_Center & "'")
Ok so I fixed that and now it gives me run-time error 3061 too few parameters. Expected 1.
What does that mean?
Ok, here is updated code, can u run it and check the immediate window
Ive added a debug.print, check the SQL that comes up, does it look valid?
also do a debug/compile as well
Private Sub Co_Cost_Center_AfterUpdate()
Dim rs As DAO.Recordset
Dim sSql As String
'Check if cost center specified
If IsNull(Me.co_cost_center) = True Then
MsgBox "No Cost Center Found"
Else
Debug.Print sSql
Set rs = CurrentDb.OpenRecordset(sSql)
'Check if cost center exists in db
If rs.EOF = True Then
MsgBox "No records found for cost center " & Me.co_cost_center
Else
Me.Hierarchy = rs!Hierarchy
Me.Market = rs!Market
Me.Region = rs!Region
End If
rs.Close
Set rs = Nothing
End If
End Sub
Ok, here is updated code, can u run it and check the immediate window
Ive added a debug.print, check the SQL that comes up, does it look valid?
also do a debug/compile as well
Private Sub Co_Cost_Center_AfterUpdate()
Dim rs As DAO.Recordset
Dim sSql As String
'Check if cost center specified
If IsNull(Me.co_cost_center) = True Then
MsgBox "No Cost Center Found"
Else
Debug.Print sSql
Set rs = CurrentDb.OpenRecordset(sSql)
'Check if cost center exists in db
If rs.EOF = True Then
MsgBox "No records found for cost center " & Me.co_cost_center
Else
Me.Hierarchy = rs!Hierarchy
Me.Market = rs!Market
Me.Region = rs!Region
End If
rs.Close
Set rs = Nothing
End If
End Sub
Now it says
Run-time error 3078
The Microsoft Jet database engine cannot find the input table or query". Make sure it exists and that its name is spelled correctly.
It points to this line
Set rs = CurrentDb.OpenRecordset(sSql)
oh bugger, my bad. I forgot to set sSql
before debug.print sSql, add this line
sSql = "SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.co_cost_center & "'"
oh bugger, my bad. I forgot to set sSql
before debug.print sSql, add this line
sSql = "SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.co_cost_center & "'"
The too few paramaters error comes up again.
In the code it highlights
Set rs = CurrentDb.OpenRecordset(sSql)
and in the immediate window it shows
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'
when u run this sql in the sql window, does it work?
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'
when u run this sql in the sql window, does it work?
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'
No it says compile error expected:case
lets get the sql working first
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'
is this the table u are reading CostCtr/Hierarchy
does it have a field called Co_Cost_Center
the error is probably due to the sql not working
lets get the sql working first
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'
is this the table u are reading CostCtr/Hierarchy
does it have a field called Co_Cost_Center
the error is probably due to the sql not working
In that table it is actually Co_Cost_Ctr
So the query should be?
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Ctr = '172/0009668'
if the above sql works, then change the code as well and try it
So the query should be?
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Ctr = '172/0009668'
if the above sql works, then change the code as well and try it
I already tried that and it gives me the same error.
Did the SQL work?
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Ctr = '172/0009668'
Did the SQL work?
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Ctr = '172/0009668'
No it gave me the same error as before.
can u confirm the name of the table/query is correct?
why not create a new query using the query wizard
Sign in to post your reply or Sign up for a free account.
Similar topics
by: leroybt.rm |
last post by:
Can someone tell me how to run a script from a interactive shell
I type the following:
>>>python filename
>>>python filename.py
>>>run...
|
by: Ed |
last post by:
Hello,
I took a course in asp about 2 years ago and I was
practicing with IIS 5.0. Then I put it down for a while.
Now trying to get back to...
|
by: Jenna Olson |
last post by:
Hi all-
I've never seen this particular issue addressed, but was wondering if
there's anything to support one way or another. Say I have a class:...
|
by: orekin |
last post by:
Hi There
I have been trying to come to grips with Application.Run(),
Application.Exit() and the Message Pump and I would really appreciate
some...
|
by: Bob Day |
last post by:
Using vs2003, vb.net
I start a thread, giving it a name before start. Code snippet:
'give each thread a unique name (for later identification)...
|
by: Bryan |
last post by:
How can i run a bit of code straight from the IDE? Right now i make a
temporary button and put the code behind that, then i run debug mode
and...
|
by: Brett Wesoloski |
last post by:
I am new to VS2005.
I changed my program.cs file to be a different form I am working on. But
when I go to run the application it still brings up...
|
by: David Thielen |
last post by:
Hi;
In our setup program how do I determine if I need to run "aspnet_regiis –i"
and if so, is there an API I can calll rather than finding that...
|
by: traceable1 |
last post by:
Is there a way I can set up a SQL script to run when the instance
starts up?
SQL Server 2005 SP2
thanks!
|
by: mxdevit |
last post by:
Task: run application from ASP.NET
for example,
you have a button on ASP.NET page, when press this button - one
application is invoked.
the...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
| |