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

Idiotproofing a form

6
I have two questions on the same form. The form (SaleMainFrm) has a subform (SalesSub). The records of the subform are entered via a Barcode scanner. I am trying to prevent the user from creating errors by entering things in the wrong places etc. So far, the error trapping that I have done is working, but there are still two things that are causing a problem:

Problem 1:
Once the sale is finished and the user has entered the “amount tendered” the focus automatically goes to a command button (“finish”). The user must then click this button (or press Enter) and the system will finish this transaction and open a new one. When a new sale is opened, the system automatically enters the information on the main form and then waits to receive the barcode in order to enter the record into the subrform. What they continually do, is forget to click the finish button, instead they scan the next barcode. This causes the system to hang for what seems like ages, but I’m sure its only a few seconds – then it goes to to the new form, where they need to scan the barcode agsin. Is there any way that I can set an event on the ‘finish’ command button that will:
1. Open a new sales form
2. Trap the barcode that the user has scanned and insert into the correct field on the new sales form.

Problem 2
Once the new sales form is created it is given an auto-number ID. This ID is used as the SaleID. I would like these numbers to run consequtively without any gaps. If the user decides after a new sales form is created, not to use it, the system will delete this ID on close. Obviously the next time they open the form, the system gives them the next number and there is now a gap in the numbers. I would like to reset the number to (1 + the last one used) . Is there a simple way to do this?
Any help would be appreciated.
Lizba
Aug 10 '10 #1
2 1164
jimatqsi
1,271 Expert 1GB
Can you try making the Finish "button" not a button at all but a text box. Add the same "on-click" event code for the text box that you have for the existing button. And if they scan anything into that text box then you will automatically run the on-click event stuff. Part of that on-click event code should check the text box for content. If there is anything in there it automatically plugs it into the correct text box for the barcodes and runs the On-Update event code or whatever code should be run when the barcode is normally done in the correct manner.

For problem 2, there are plenty of examples here of maintaining Next ID numbers. Here's some code, I don't remember if I wrote this or if it came from another poster here. It is a function that returns a unique ID for the requested table.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function NextID(strTable, Optional strPrefix, Optional bVerify As Boolean) As String
  5. Dim dbs As DAO.Database
  6. Dim rs As DAO.Recordset
  7. Dim lngNextID As Long
  8. Dim rsTargetTbl As DAO.Recordset    '
  9. Dim strSQL As String
  10.  
  11. ' strTable is the table we want to form a new key for
  12. ' strPrefix is an optional prefix for the formulated key
  13. ' bVerify indicates whether to verify the key is unique or not
  14.  
  15. On Error GoTo Err_NextID
  16.  
  17. Set dbs = CodeDb
  18. NextID = ""
  19. Do Until NextID <> ""
  20.     ' select only the row containing the ID for the selected table
  21.     strSQL = "Select * from tblTableIDs where strTableName=""" & strTable & """"
  22.     Set rs = dbs.OpenRecordset("tblTableIDs", dbOpenDynaset, dbSeeChanges)
  23.         rs.Edit
  24.             lngNextID = rs!NextID + 1
  25.             rs!NextID = lngNextID
  26.         rs.Update
  27.  
  28.         If Nz(strPrefix, "") = "" Then ' was a prefix supplied?
  29.             NextID = Format(lngNextID, "000000") ' you might want a different format
  30.         Else
  31.             NextID = strPrefix & Format(lngNextID, "000000") ' add the prefix to the key
  32.         End Function
  33.     rs.Close
  34.  
  35.     If Nz(bVerify, False) = True Then
  36.         strSQL = "select ID from " & strTable & " where ID=""" & NextID & """"
  37.         Set rsTargetTbl = dbs.OpenRecordset(strSQL, dbReadOnly)
  38.         If Not rstargetbl.EOF Then
  39.             NextID = "" ' can't use this ID because it is already in the table
  40.         End If
  41.         rsTargetTbl.Close
  42.     End If
  43. Loop        ' until nextid is not ""
  44.  
  45. Exit_NextID:
  46.     rs.Close
  47.     rsTargetTbl.Close
  48.     Set rs = Nothing
  49.     Set rsTargetTbl = Nothing
  50.     Set dbs = Nothing
  51. Exit Function
  52.  
  53. Err_NextID:
  54.     NextID = ""
  55.     GoTo Exit_NextID
Jim
Aug 11 '10 #2
lizba
6
Brillian idea about the text box, that will definately work. I'll try out the code as well. Thanks for all you help.
Lizba
Aug 12 '10 #3

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

Similar topics

3
by: John | last post by:
Dear all, It been more than 3 days I am trying to debug this program, I interpret it using activePerl and it is giving (perl -wc code_process.pl) no error syntax but when I put it online, change...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
4
by: Targa | last post by:
Trying to total some price fields in a form but doesnt work when all the referenced form fields dont exisit. This is for an invoice - pulled prom a database and the form doesnt always contain the...
19
by: Raposa Velha | last post by:
Hello to all! Does any of you want to comment the approach I implement for instantiating a form? A description and an example follow. Cheers, RV jmclopesAThotmail.com replace the AT with the...
11
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
4
by: Alex Sibilev | last post by:
Hello, I have a really weird problem I've been trying to solve it without any luck for the last couple of hours :( I'm writing a "conference board" application (quite similar to ASP.NET...
5
by: ortaias | last post by:
I have a form which calls up a second form for purposes of data entry. When closing the data entry form and returning to the main form, things don't work as expected. When I return to the main...
3
by: Bill | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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$) { } ...
0
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...
0
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...
0
BarryA
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 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.