473,837 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining Code

173 New Member
Hi,

I have got an ADD button with the following code:

Private Sub addrec_Click()
On Error GoTo Err_addrec_Clic k

DoCmd.GoToRecor d , , acNewRec

Exit_addrec_Cli ck:
Exit Sub

Err_addrec_Clic k:
MsgBox Err.Description
Resume Exit_addrec_Cli ck

End Sub


and i have some validations through the following code:

Private Sub Form_BeforeUpda te(Cancel As Integer)

Dim blnValidation As Boolean
Dim strValidate As String

strValidate = "These item(s) were not filled out and are required:" & vbCrLf & vbCrLf

If IsNull(Me.usern ame) Or Me.username = "" Then
blnValidate = True
strValidate = strValidate & "Username" & vbCrLf
End If

If IsNull(Me.numbe r) Or Me.number = "" Then
blnValidate = True
strValidate = strValidate & "Number" & vbCrLf
End If

If blnValidate Then
MsgBox strValidate
Cancel = True
End If

End Sub


The question...... how do i combine these codes and have an ADD button that will show a validation message before updating anything??

i cant seem to get this right? somat always goes wrong? i do not want the add button to add anything until the form is complete?
Nov 29 '06 #1
74 6457
NeoPa
32,584 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. Private Sub AddButton_Click()
  2.     'Do validation checks
  3.     If blnValidate Then
  4.         MsgBox strValidate
  5.     Else
  6.         'Add new record
  7.         DoCmd.GoToRecord , , acNewRec
  8.     End If
  9. End Sub
Nov 30 '06 #2
Beany
173 New Member
thanks Neo,

that code doesnt work........... ... ive tried the following...... .... what am i doing wrong?

[HTML]Private Sub addrec_Click()
'Do validation checks


Dim blnValidation As Boolean
Dim strValidate As String

strValidate = "These item(s) were not filled out and are required:" & vbCrLf & vbCrLf

If IsNull(Me.usern ame) Or Me.username = "" Then
blnValidate = True
strValidate = strValidate & "Username" & vbCrLf
End If

If blnValidate Then
MsgBox strValidate
Else
'Add new record
DoCmd.GoToRecor d , , acNewRec
End If

End Sub[/HTML]
Nov 30 '06 #3
Beany
173 New Member
any1 have an idea??
Dec 4 '06 #4
markmcgookin
648 Recognized Expert Contributor
any1 have an idea??
Could you split the code into sub routines, then call them in order?

i.e.

btn_click ... ()

sub_validate1()

sub_validate2()

end sub

sub_validate1 ... ()

end sub

sub_validate2()

end sub

Something like that?
Dec 4 '06 #5
NeoPa
32,584 Recognized Expert Moderator MVP
You spelt blnValidation in the Dim statement but blnValidate when referring to it.
As the check is so simple, you don't need it anyway ;).
As the string is also only set and used once each, it too is unnecessary.
Try this :
Expand|Select|Wrap|Line Numbers
  1. Private Sub addrec_Click()
  2.     If Nz(Me.username, "") = "" Then
  3.         MsgBox "These item(s) were not filled out " & _
  4.                "and are required:" & vbCrLf & vbCrLf & _
  5.                "Username" & vbCrLf
  6.     Else
  7.         'Add new record
  8.         DoCmd.GoToRecord , , acNewRec
  9.     End If
  10. End Sub
I made the code narrower with the line continuation character (_) to display more easily in here but that is not important to the code working.
BTW Code indentation also doesn't affect the way the code works, but is invaluable to help a reader understand what is happening where.
Dec 4 '06 #6
Beany
173 New Member
Neo you're a star.......

just another question....... .....

the code you provided shows that if the USERNAME field is missed a validation message occurs.(which is good).......... .....

how would i add more fields to that....... for eg, phone number, imei code etc.....

so it brings up a list of all the fields ive missed?
Dec 4 '06 #7
NeoPa
32,584 Recognized Expert Moderator MVP
Then you would use a string variable.
Give me some time and I'll post some code to give an example.
Dec 4 '06 #8
NeoPa
32,584 Recognized Expert Moderator MVP
Assuming IMEI code is numeric & Phone Number is a string :
Expand|Select|Wrap|Line Numbers
  1. Private Sub addrec_Click()
  2.     Dim strMsg As String
  3.     Dim blnValidate As Boolean
  4.  
  5.     strMsg = "These item(s) were not filled out " & _
  6.              "and are required:" & vbCrLf & vbCrLf
  7.     blnValidate = False
  8.     If Nz(Me.username, "") = "" Then
  9.         blnValidate = True
  10.         strMsg = strMsg & "Username" & vbCrLf
  11.     ElseIf Nz(Me.Phone_No, "") = "" Then
  12.         blnValidate = True
  13.         strMsg = strMsg & "Phone Number" & vbCrLf
  14.     ElseIf Nz(Me.IMEI_Code, 0) = 0 Then
  15.         blnValidate = True
  16.         strMsg = strMsg & "IMEI" & vbCrLf
  17.     End If
  18.     If blnValidate Then
  19.         MsgBox strMsg
  20.     Else
  21.         'Add new record
  22.         DoCmd.GoToRecord , , acNewRec
  23.     End If
  24. End Sub
Dec 4 '06 #9
Beany
173 New Member
ur good........... and quick.........

il give that a try........ thank you very much........

appreciate it Neo
Dec 4 '06 #10

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

Similar topics

4
2425
by: John | last post by:
I currently have a list box that contains regions in the US (Northeast, Midwest, South, etc.). I am retrieving this data from my Region table(see below). Users have the ability to select a region as part of a search. The results were too broad so we had to make an Office table. Region Table RegionCd varchar(2) RefionDesc varchar(50)
2
2751
by: Brian | last post by:
Hi All, Can someone please point me in the right direction I am having problems combining JS and ASP. What I am trying to do is store in a database using ASP the referring page of my visitors. I got the ASP working great and when I use the document.referrer in an alert it works too, but when I try to combine the 2 languages that is when I get an error that I cannot fix. Here is the code fragment that is not working: rs("ReferPage")...
3
1477
by: Unregistered | last post by:
Hello! I came across two different scripts that I wanted to combine, and I thought I wa successful until I discovered a minor glitch. What was happening was that the page that was linked to came out fine but the page where the link was was linking out to another page . Here's what my code looks like.
2
3281
by: Chris Mullins | last post by:
I've spent a bit of time over the last year trying to implement RFC 3454 (Preparation of Internationalized Strings, aka 'StringPrep'). This RFC is also a dependency for RFC 3491 (Internationalized Domain Names / IDNA) which is something that I also need to support. The problem that I've been struggling with in .NET is that of Unicode Code Points > 0xFFFF. These points are encoded into UTF8 using the Surrogate Pair encoding scheme that...
3
1736
by: alwayswinter | last post by:
I currently have a form where a user can enter results from a genetic test. I also have a pool of summaries that would correspond to different results that a user would enter into the form. I ideally I would like to have the user enter their results and then have a master summary created with the different word or HTML files on submit. (condition 1 + condition 2 = combining/displaying corresponding HTML files) I've gotten as far as...
7
4825
by: Barry | last post by:
Hi all, I've noticed a strange error on my website. When I print a capital letter P with a dot above, using & #7766; it appears correctly, but when I use P& #0775 it doesn't. The following capital letters all work correctly - B C D F G M S T with the diacritical marker &#_0775. Why am I having a problem with P?
5
2115
by: M.Stanley | last post by:
Hi, I'm attempting to create a query that will combine 2 columns of numbers into one. The followng comes from 1 table with 4 fields (A,B,C,D) A B RESULT 700 000 700000 700 001 700001 700 002 700002 ..
3
2229
by: Flip | last post by:
I'm looking at the O'Reilly Programming C# book and I have a question about extending and combining interfaces syntax. It just looks a bit odd to me, the two syntaxes look identical, but how does C# know which is extending and which is combining? interface IStorable{ void Read(); void Write(object o); }
5
5647
by: Tristan Miller | last post by:
Greetings. Is it possible using HTML and CSS to represent a combining diacritical mark in a different style from the letter it modifies? For example, say I want to render Å‘ (Latin small letter o with a double acute accent), but with the o in black and the double acute accent in green. Are either of the following valid? 1. <span style="color: black;">o</span><span style="color: green;">&#x030B;</span>
3
2852
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one dataset to data in a second dataset, using a common key. I will first describe the problem in words and then I will show my code, which has most of the solution done already. I have built an ASP.NET that queries an Index Server and returns a...
0
9678
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10609
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10263
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7798
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5838
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4468
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4034
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3120
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.