473,513 Members | 2,561 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return from MsgBox to Form Stalling

6 New Member
First, thanks in advance for any assistance given! I'm working in Microsoft Access 2007 on a data base developed by someone no longer with the company.

The database I'm working on is designed for parts to be entered with a specific SKU/Identification number and is running on seperate computers. The original developer set a starting point for the SKU number that works but its usage has grown beyond its original intentions. I was asked to add code into the form so a range could be set on each computer as to prevent duplicates when the data is compiled to a central computer. I entered the following code which sets up the range and functions but once the range is met you have to click the okay button 16 times to return to the form. Any help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeInsert(Cancel As Integer)
  2. If DCount("*", "SKU Data") >= 1 Then
  3. Cancel = True
  4. MsgBox "Only 1 record allowed!  Contact Kevin for assistance!"
  5. End If
  6. End Sub
  7.  
Sep 29 '11 #1
11 2066
patjones
931 Recognized Expert Contributor
I take it that you don't have a network drive on which to setup a single back end file?

Just by looking at your code, I can't really say why you need to click the OK button 16 times to get out of the dialog box. However, I can suggest a couple of things that will bring your code more in line with good practice and might perhaps fix your problem.

I would first use the BeforeUpdate event for the text box that is taking the SKU number in; second, I would write the DCount( ) call with more specifics in the arguments, and actually use the third argument which calls for criteria. So for instance, assuming a text box name of txtSKU, and a field name of fldSKU in the table:

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSKU_BeforeUpdate(Cancel As Integer)
  2.  
  3. If DCount("fldSKU", "SKU Data", "fldSKU = " & Me.txtSKU) > 0 Then
  4.    Cancel = True
  5.    MsgBox "Only one record per SKU allowed!"
  6. End If
  7.  
  8. End Sub

What do you think? If I've misunderstood anything then let me know and we can refine the response.

Pat
Sep 29 '11 #2
EufJoe
6 New Member
Thanks Pat. The databases is being run on laptops at different locations and what they are looking for is a range of 1000 on each computer. I apologize as my having the code set to 1 probabply miss led you, (I was keeping a low number so not to have to key in but one record to test).

Thanks,
Joe
Sep 29 '11 #3
Mihail
759 Contributor
Hi all !
Hope I understand OK your problem.
So, I think you can use the LOAD event of the form to check if there is a record. If YES then set the Allow Additions property to No.
Also you can design a label where you can inform the user that maximum numbers of records is reached.
Sep 30 '11 #4
patjones
931 Recognized Expert Contributor
@Mihail:

I'm not sure how the On Load event for the form is relevant here. If I'm understanding the OP's issue correctly, he wants to make sure that upon starting a new record entry, the user does not commit a duplicate SKU to the table. The form would already be loaded at that point.

Also, the Allow Additions property is relevant only in the context of a bound form. The OP has not indicated to us whether or not he is using a bound or unbound form.

EufJoe...can you let us know whether or not we're on the right track here, and in particular whether you've tried to implement the Before Update code in my previous post? Thanks.
Sep 30 '11 #5
EufJoe
6 New Member
@Mihail

Thanks for your assistance! I believe zepphead80 is correct and I've used part of his original suggestion and have it working now.

@zepphead80
I'm not sure why but for some reason when I call the code out by field names as you suggested it ran with no exceptions under "Before Update" but failed to hold the range. I just finished entering my original code under "Before Update" and it is working and holding the range without having to click "Okay" 16 times as I was having to earlier.

Thanks again for all your help and hopefully one day I will be able to return the favor,
Joe
Sep 30 '11 #6
patjones
931 Recognized Expert Contributor
Joe,

I'm glad that it's working better for you now. Can you clarify what you mean by 'hold the range'?
Sep 30 '11 #7
EufJoe
6 New Member
Pat,

Range may not have been my best choice of words, "limit" probably would have been a better choice. The "SKU" number field is currently populated with 30,000 entries and they are planning to run this database on multiple computers at random locations. What they are wanting is to set a 1,000 entry range or limit on each computer and then set the "SKU" number accordingly to prevent duplicates, (computer 1 - SKU set to begin at 30,000, computer 2 - SKU set to begin at 31,000 and so on) with each database holding a 1,000 entry limit as not to encroach on another users assigned "SKU" range or limit.

Thanks again,
Joe
Sep 30 '11 #8
patjones
931 Recognized Expert Contributor
OK, then there's a subtle point that we're uncovering here. The code that I gave you has nothing to do with range checking. It simply checks to see if the SKU that the user is inputting is already in the table. It's a duplicate checker, essentially.

For checking on the range, you could append my code like this, for example:

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSKU_BeforeUpdate(Cancel As Integer)
  2.  
  3. If Me.txtSKU < 30000 Or Me.txtSKU > 30999 Then
  4.    Cancel = True
  5.    MsgBox "SKU out of range!"
  6. Else
  7.    If DCount("fldSKU", "SKU Data", "fldSKU = " & Me.txtSKU) > 0 Then
  8.       Cancel = True
  9.       MsgBox "Only one record per SKU allowed!"
  10.    End If
  11. End If
  12.  
  13. End Sub

This requires you to set the range appropriately on each computer. One way to minimize the tedious nature of this task is to define the lower and upper limits as constants at the top of the module:

Expand|Select|Wrap|Line Numbers
  1. Public Const SKU_low = 30000
  2. Public Const SKU_upper = 30999

Then you simply use the constant names everywhere in the code in place of the actual values. Just a suggestion!

Pat
Sep 30 '11 #9
EufJoe
6 New Member
Thanks Pat! I'll apply this and let you know the outcome.

I apologize if I failed to state this correctly, this is my first time posting to a site like this and was trying to keep it brief as per instructions.

Again, thanks for all your help,
Joe
Sep 30 '11 #10
EufJoe
6 New Member
@zepphead80

Pat, your code worked perfect and you taught me something new.

Thanks for all your help,
Joe
Sep 30 '11 #11
patjones
931 Recognized Expert Contributor
Joe it's no problem. I should also point out that you posted your question just fine as far as I'm concerned. It is not uncommon for issues to take ten or more posts to come to full resolution.

Enjoy your weekend...

Pat
Sep 30 '11 #12

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

Similar topics

3
4966
by: Bruce Dodds | last post by:
I'm trying to set a tabledef object from a form object's RecordSource in Access 97. This is the code: Public Function EditSubjectForm(ByVal frm As Form) As Boolean Dim db As Database, tbl As...
8
2478
by: Prakash | last post by:
I have a msgbox in my form activate event with an OK button. However the msgbox shows up BEFORE the form is painted. I would like the msgbox to be visible after the form gets painted on...
7
1108
by: anthony | last post by:
I tried sth i did b4 in VB, now in VB.NET, but since the form is created every time, the following code would not work because MsgBox.Visible is always false, any idea? Thanks! Public...
1
1581
by: Richard | last post by:
Hi Gurus, Is it possible to fire Msgbox or a Form from a Windows Service. I'll appreciate your help. Thanks in advance. Richard
6
3154
by: Thelma Lubkin | last post by:
I am trying to modify an Access form that allows a user to specify the information s/he needs from a census-type database. The form's code builds a SQL statement from the user's request, and...
1
3145
by: shobana | last post by:
Hi I have a bunch of checkboxes. While in fetch method iam checking it and disabling the checkbox which has data in backend. Rest are enabled. User can check the rest and update it. While in form...
0
955
by: ropo | last post by:
I have a 2.0 .NET windows application, in this application I start an external win32 Process the wait for it to finish. When I close the external process my main application form goes to the back...
1
3763
by: genius.jain | last post by:
HI i am opening a form as showdialog In amin form MDI Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click Try Dim...
2
4589
by: inx3us | last post by:
My simple code to send Form fields to Outlook: Dim strMsgBody As String Dim strSubject As String strSubject = "Subject is here" strMsgBody = "Body." " COMPANY NAME: " + Text82 & " CUSTOMER...
2
4408
by: vamsirays | last post by:
how can we use these escape sequence, and also octal number(\010) and hexadecimal number given(\xhh)?
0
7259
marktang
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,...
0
7535
jinu1996
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...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.