473,322 Members | 1,538 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,322 software developers and data experts.

GetLineNumberFunction() is not working

3
Hi,

Good Day!

I have a form with a subform and I want to have a line number for each of the records that will be displayed.

Here is my setup:


I have a table with the field "ID" with the setup "Integer".

I have a module called GetLNumber and put this code

Expand|Select|Wrap|Line Numbers
  1. Function GetLineNumber(F As Form, KeyName As String, KeyValue)
  2.  
  3. Dim RS As DAO.Recordset
  4. Dim CountLines
  5.  
  6. On Error GoTo Err_GetLineNumber
  7.  
  8. Set RS = F.RecordsetClone
  9.  
  10. ' Find the current record.
  11. Select Case RS.Fields(KeyName).Type
  12. ' Find using numeric data type key value.
  13. Case dbInteger, dbLong, dbCurrency, dbSingle, dbDouble, dbByte
  14. RS.FindFirst "[" & KeyName & "] = " & KeyValue
  15. ' Find using date data type key value.
  16. Case dbDate
  17. RS.FindFirst "[" & KeyName & "] = #" & KeyValue & "#"
  18. ' Find using text data type key value.
  19. Case dbText
  20. RS.FindFirst "[" & KeyName & "] = '" & KeyValue & "'"
  21. Case Else
  22. MsgBox "ERROR: Invalid key field data type!"
  23. Exit Function
  24. End Select
  25.  
  26. ' Loop backward, counting the lines.
  27. Do Until RS.BOF
  28. CountLines = CountLines + 1
  29. RS.MovePrevious
  30. Loop
  31.  
  32. Bye_GetLineNumber:
  33. ' Return the result.
  34. GetLineNumber = CountLines
  35.  
  36. Exit Function
  37.  
  38. Err_GetLineNumber:
  39. CountLines = 0
  40. Resume Bye_GetLineNumber
  41. End Function
and then in the textbox called txtID has a Control Source =GetLineNumber([Forms]![frmEarlyWarningSystem].[Form].[frmEarlyWarningSystemSubform],"ID",[ID])

but when I click Form View, the field for txtID contains #Type!

I tried this code also but still no luck.

Expand|Select|Wrap|Line Numbers
  1. Function GetLineNumber(F As Form, KeyName As String, KeyValue)
  2. Dim RS As Object
  3. Dim CountLines
  4.  
  5. On Error GoTo Err_GetLineNumber
  6.  
  7. Set RS = F.Recordset.Clone
  8.  
  9. RS.Find "[" & KeyName & "] = " & KeyValue
  10.  
  11. ' Loop backward, counting the lines.
  12. Do Until RS.BOF
  13. CountLines = CountLines + 1
  14. RS.MovePrevious
  15. Loop
  16.  
  17. Bye_GetLineNumber:
  18. ' Return the result.
  19. GetLineNumber = CountLines
  20.  
  21. Exit Function
  22.  
  23. Err_GetLineNumber:
  24. CountLines = 0
  25. Resume Bye_GetLineNumber
  26.  
  27. End Function
what did I missed?

Your help is very much appreciated!

tia
Apr 9 '13 #1
3 1331
NeoPa
32,556 Expert Mod 16PB
If it allows you to pass a form reference then you could try :
Expand|Select|Wrap|Line Numbers
  1. =GetLineNumber([Forms]![frmEarlyWarningSystem]![frmEarlyWarningSystemSubform]![Form],"ID",[ID])
Your reference to the subform object was incorrect (wrong order of elements) and SQL doesn't recognise dots (.), so this is worth a try.

See Referring to Items on a Sub-Form for correct structure of references from VBA.
Apr 9 '13 #2
blur
3
Thanks NeoPa for your quick response. I've tried it but still not working. it displays "#Name?"

here is the new value of control source of my textbox

Expand|Select|Wrap|Line Numbers
  1. =GetLineNumber([Forms]![frmEarlyWarningSystem]![Form]![frmEarlyWarningSystemSubform]![Form],"ID",[ID])
Apr 9 '13 #3
NeoPa
32,556 Expert Mod 16PB
That won't work. If you look at the linked article you'll clearly see why.

Expand|Select|Wrap|Line Numbers
  1. [Forms]![frmEarlyWarningSystem]
Is a reference to a form object. Form objects don't have Form properties (After all - what would be the point?).

Subform controls, however, are not Form objects at all, but contain a Form. That is why it makes sense that they would have a Form property.

It's all in the linked article.

You may well find, however, that there are limits to what you can refer to at all from within SQL. That's not something I can help with I'm afraid.
Apr 10 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Gary | last post by:
I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)"); This is not working ..what could be the...
6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
3
by: | last post by:
Hello, I am hoping someone else has thought about a date time calculation i need to perform. I would like to be able to calculate the number of "working minutes" between 2 dates, given my...
8
by: Hardy Wang | last post by:
Hi: Is it possible for me to create/open web application from remote machine other than port 80? And create application directly under virtual web site instead of creating a virtual directory?...
4
by: GP | last post by:
We are facing a strange problems everything works fine when we are using the visual studio environment .But when we deploy it in the webserver the save buttons/submit buttons which has the cause...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.