Hi all,
I am having a problem with a PO database. I am trying to create a field that auto generates a PO line number. I have create a module (given in microsoft office help). When I try to use this function in a text box on the sub form I get an error " the object doesnot contain the automation object "Get Line Number" and #Name? is displayed.
the command in the control source is =GetLineNumber([Form],"ID",[ID])
ID being an auto number unique to the line item in the table.
Help please
22 8633 Banfa 9,065
Expert Mod 8TB
This is not the correct forum for this POST it should be in a relevent database forum.
For now I am moving it to Access (because that seems to be quite popular) but you are unlikely to get a satisfactory answer until you tell us what sort of database you are using.
Please read the Posting Guidelines.
Banfa
Administrator
Thanks - as you have prob notice I'm new to this. The database i'm working in is microsoft Access 2003.
You'll really need to give us a better explanation of what you're trying to do if we're to help you!
For instance, what's a PO number/PO Line number? Post Office? Purchase Order? And exactly what are you trying to accomplish?
We also need the code for the function GetLineNumber().
Welcome to TheScripts!
Linq ;0)>
You'll really need to give us a better explanation of what you're trying to do if we're to help you!
For instance, what's a PO number/PO Line number? Post Office? Purchase Order? And exactly what are you trying to accomplish?
We also need the code for the function GetLineNumber().
Welcome to TheScripts!
Linq ;0)>
Ok
Purchase order line number - I am trying to auto number the line items on a subform.
I have used this module to obtain the function GetLineNumber( ) - Option Compare Database
-
Option Explicit
-
-
'============================================================
-
' The following function is used by the subLineNumber form
-
'============================================================
-
-
Function GetLineNumber(F As Form, KeyName As String, KeyValue)
-
Dim rs As Object
-
Dim CountLines As Integer
-
-
On Error GoTo Err_GetLineNumber
-
-
Set rs = F.Recordset.Clone
-
-
' Find the current record.
-
Select Case rs.Fields(KeyName).Type
-
' Find using numeric data type key value?
-
Case adSmallInt, adTinyInt, adBigInt, adInteger, adDecimal, adNumeric, adCurrency, adSingle, adDouble
-
rs.FindFirst "[" & KeyName & "] = " & KeyValue
-
' Find using date data type key value?
-
Case adDate
-
rs.FindFirst "[" & KeyName & "] = #" & KeyValue & "#"
-
' Find using text data type key value?
-
Case adChar, adVarChar
-
rs.FindFirst "[" & KeyName & "] = '" & KeyValue & "'"
-
Case Else
-
MsgBox "ERROR: Invalid key field data type!"
-
Exit Function
-
End Select
-
-
' Loop backward, counting the lines.
-
Do Until rs.BOF
-
CountLines = CountLines + 1
-
rs.MovePrevious
-
Loop
-
-
Bye_GetLineNumber:
-
' Return the result.
-
GetLineNumber = CountLines
-
-
Exit Function
-
-
Err_GetLineNumber:
-
CountLines = 0
-
Resume Bye_GetLineNumber
-
-
End Function
I then placed a unbound textbox in the subreport of a purchase order form. (the subreport is the line items).
in the control I used this; =GetLineNumber([Form],"ID",[ID]
I have taken all of this from a microsoft sample database. I have tried renaming forms, ID etc.
In the Purchase order Line table ID is an auto number field (primary field) for all the records.
I have also moved this text field to the first row of the tab order. The error I get in the box is #Name?
I think this is as much as I know / capable of hope its a bit clearer now.
Thanks again
I don't have time to go into this in detail right now, but the one thing that stands out in a quick scan is your line
in the control I used this; =GetLineNumber([Form],"ID",[ID]
You have to actually insert the name of your form here, in quotes:
=GetLineNumber( "YourFormNameGoesHere","ID",[ID])
There may be other issues, but that's a start. I'll look back later, when I get a chance, but try that for now. In the meantime, maybe someone else will take a look at it for you.
Linq ;0)>
Yes, that was my inital thought but when I put a name in there I get the error "The object does not contain the automation object 'GetLineNumber'.
I have tried every verison of form names, query name (of which the form is based), table name.
In the example form I saw this on it was actual [Form] that used not the form name. http://support.microsoft.com/kb/325236/en-us
is the link to where I saw this and have taken the code from.
Any way thanks for your help - there's no rush it puzzled me for weeks so I'd pretty well given up on it anyway.
Assuming it's code "behind" the form needed by the function you could pass the form object by using:
=GetLineNumber(Me,"ID",[ID])
as Me points to the form.
Nic;o)
Take a look again at line 9: This needs to be Dim rs As DAO.Recordset (as in the example from the MS website you posted), not As Object.
And then, as Linq suggested, you need to put the form's name into the parameters you pass.
Regards,
Scott
Also, I noticed that you have changed the data types in the Select Case statement. Is this for purposes of working with VB6? The original data types in the example on MS's website are more than enough for working with VBA.
Another point is that you should close the recordset at the end of your code block, as leaving them open can tend to cause problems later on.
rs.Close
Set rs = Nothing
Should be included in any code that opens a recordset.
Regards,
Scott
Thanks for that - still have the same error though. I've typing it in VB as opposed to cut and paste in case other errors had transferred over.
Must be an issue some where else might try making a small simple database and seeing if it works there. I let you know the outcome.
The changes you have noticed are from the VB script of the sample database that this command was working in. I thought the diffences in versions may make a difference so I have tried both. I just didn't realise I'd left the old version in my database when i copied and pasted my vb on this page.
I have to be honest and say I now very little about VB so technically its a bit above me.
Thanks for your time
PT
Hmm, when you want to solve this without code you could use a query with the DCOUNT() function like: -
select Dcount("ID","query_of_subform","POnumber=" & [POnumber] & " AND [ID} <=" & [ID]) as LineCountPO, POnumber, ID, .... from tblPurchaseOrders;
-
This will create a linenumber in the query and you can place the [LineCountPO] "straight away" in your subform.
Nic;o)
Maybe you've said and I missed it, if so, forgive me, but exactly where do you have the GetLineNumber() function? Is it in the code for the main form, the code for the subform or in a standard module?
Linq ;0)>
Linq,
What I have done is created GetLineNumber() in a module. Then on the subform I have placed a text box in in the control source I have used the expression builder to use the function "GetLineNumber()" which is now available to select. The expression gives
GetLineNumber(<<F>>,<<KeyName>>,<<KeyValue>>)
I then put in the relevant fields and then the problem starts.
PT
Hmm, when you want to solve this without code you could use a query with the DCOUNT() function like: -
select Dcount("ID","query_of_subform","POnumber=" & [POnumber] & " AND [ID} <=" & [ID]) as LineCountPO, POnumber, ID, .... from tblPurchaseOrders;
-
This will create a linenumber in the query and you can place the [LineCountPO] "straight away" in your subform.
Nic;o)
Nico
Forgive my ignorance but in this example are you wwriting this code in a new module? or in an event procedure or in the query its self?
To be honest I think I should just forget this as I think my serious lack of programing skills may be wasting your time!
I think I need to go and have some training as opposed to self taught
Thanks
PT
What I have done is created GetLineNumber() in a module.
You didn't, by chance, also name the module GetLineNumber? People often do this, and it confuses the Access gnomes! If you have, you need to rename the module.
Linq ;0)>
You didn't, by chance, also name the module GetLineNumber? People often do this, and it confuses the Access gnomes! If you have, you need to rename the module.
Linq ;0)>
Yes I did - changed it and it works!!!
Thank you for persistance
Glad we finally figured it out!
Linq ;0)>
Nico
Forgive my ignorance but in this example are you wwriting this code in a new module? or in an event procedure or in the query its self?
To be honest I think I should just forget this as I think my serious lack of programing skills may be wasting your time!
I think I need to go and have some training as opposed to self taught
Thanks
PT
My sample is, like posted, purely a query and requires no code.
The Dcount() function can be used in a query and will give the linenumber because it counts the number or rows for the specified key and only those where the "subkey" is less or equal.
Good find that modulename linq !
Hard for me to figure, as I always start my modulenames with "mod" :-)
Nic;o)
Unless you teach or spend an awful lot of time in forums like this one, it can be easy to forget the very basic mistakes that many people make. Being in forced retirement, I have the time to contribute here, as well as to four other Access forums, on a regular basis. This is the 4th thread I've seen today where the problem was having the module and function named the same!
Linq ;0)>
what about the new record?
what is the iif statement for : don't show a linenumber for a new record?
I wanted a "x . y" number and changed the textboxcontrolsource to
=IIf([newrecord]=True;"";GetLijnNr([Form];"PrimIDTstblwoningen";[PrimIDTstblwoningen]) & " . " & Count(*))
vdzr,
You have asked your question in another member's thread. This is called thread hijacking and is not allowed on this site. There are various reasons for this, the principal of which is that it typically diverts the flow of the thread away from his needs and into yours. Another is that it will tend to mean that your new question is not seen as such, and may get overlooked by many of our experts (You appreciate that they're not looking for answered questions).
Please post your questions in their own threads in future (See How to Ask a Question).
MODERATOR
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mantorok Redgormor |
last post by:
what is the purpose of the #line directive?
how is it suppose to be used?
I didn't see it mentioned in the faq and I can't make any sense of it from
the standard.
--
nethlek
|
by: vishal |
last post by:
What does
#line 182 parser.y
mean in a C program?
|
by: Skybuck Flying |
last post by:
Hi,
I needed a method to determine if a point was on a line segment in 2D. So I
googled for some help and so far I have evaluated two methods.
The first method was only a formula, the second...
|
by: Ken Varn |
last post by:
I want to be able to determine my current line, file, and function in my C#
application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___
macros for getting this, but I cannot find a...
|
by: Gary Wessle |
last post by:
hi
I have a data file with equal number of columns for each row. I need
to get the number of rows and columns to allocate a matrix in gsl.
getline (in, line) and parse the line for the number of...
|
by: Adi |
last post by:
Hello eveyone,
I wanna ask a very simple question here (as it was quite disturbing
me for a long time.)
My problem is to read a file line by line. I've tried following
implementations but still...
|
by: Jeff Jarrell |
last post by:
I have a block of code that during development is prone to casting errors.
It is mostly a DataReader type thing.
It looks something like this.
_prtPNID = myDLReader.GetString("prtPNID")...
|
by: Mark |
last post by:
Hi All,
I have wrote a sub to record events from within the database. A lot of
these events are errors. The sub has the module name and function/sub name
passed to it to record to the table. My...
|
by: Horacius ReX |
last post by:
Hi,
I have to search for a string on a big file. Once this string is
found, I would need to get the number of the line in which the string
is located on the file. Do you know how if this is...
|
by: J.H.Kim |
last post by:
Hi, everyone
I saw the preprocessor "#line " in some source codes.
It was like this :
#line 2972 "ifupdown.nw"
Please tell me what is the meaning of that "#line"?
Thanks in advance.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: 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: 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: 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,...
|
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: 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...
| |