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

Saving the record

i have been using this code to save my unbound form data into the table.
if no data has been entered and the save button is pressed a MSG box should be shown but i am getting an error 13
plz help me out

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Enter()
  2.  
  3.     If (Me!Text0.Name And Me!Text2.Name = Null) Then
  4.         MsgBox "This record is blank. Please Enter something to save" _
  5.              , vbInformation, "Invalid Action"
  6.         Exit Sub
  7.     Else
  8.         Dim strQry As String
  9.  
  10.         strQry = "INSERT INTO [Table1] ([voc_no],[name]) Values ('" & Me!Text0 & "','" & Me!Text2 & "')"
  11.         DoCmd.RunSQL strQry
  12.     End If
  13. End Sub
  14.  
Apr 25 '07 #1
7 1526
pks00
280 Expert 100+
U dont check for null like u have, is IsNull instead
i.e.
If IsNull(Me.Text2) = True then
msgbox "Null field entered"
Apr 25 '07 #2
thanx a lot. i made a mistake.
Apr 25 '07 #3
when i press the save button the msg box saying that you are appending a record comes which is a default Msg in Access.
i dont want that to come instead i want that the msg defined by me should come.
this the code i am using.
plz help me out with it

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Enter()
  2.  
  3.     If IsNull(Me.Text0) = True Then
  4.         MsgBox "This record is blank. Please Enter something to save" _
  5.              , vbInformation, "Invalid Action"
  6.         Exit Sub
  7.     Else
  8.         Dim strQry As String
  9.  
  10.         strQry = "INSERT INTO [Table1] ([voc_no],[name]) Values ('" & Me!Text0 & "','" & Me!Text2 & "')"
  11.         DoCmd.RunSQL strQry
  12.         MsgBox "Do you want to save the record", vbOKOnly, "Alert"
  13.     End If
  14. End Sub
  15.  
Apr 25 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
This will turn off the warnings

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Enter()
  2.     DoCmd.SetWarnings False
  3.     If IsNull(Me.Text0) = True Then
  4.         MsgBox "This record is blank. Please Enter something to save" _
  5.              , vbInformation, "Invalid Action"
  6.         Exit Sub
  7.     Else
  8.         Dim strQry As String
  9.  
  10.         strQry = "INSERT INTO [Table1] ([voc_no],[name]) Values ('" & Me!Text0 & "','" & Me!Text2 & "')"
  11.         DoCmd.RunSQL strQry
  12.         MsgBox "Do you want to save the record", vbOKOnly, "Alert"
  13.     End If
  14.     DoCmd.SetWarnings True
  15. End Sub
  16.  
Apr 25 '07 #5
This will turn off the warnings

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Enter()
  2.     DoCmd.SetWarnings False
  3.     If IsNull(Me.Text0) = True Then
  4.         MsgBox "This record is blank. Please Enter something to save" _
  5.              , vbInformation, "Invalid Action"
  6.         Exit Sub
  7.     Else
  8.         Dim strQry As String
  9.  
  10.         strQry = "INSERT INTO [Table1] ([voc_no],[name]) Values ('" & Me!Text0 & "','" & Me!Text2 & "')"
  11.         DoCmd.RunSQL strQry
  12.         MsgBox "Do you want to save the record", vbOKOnly, "Alert"
  13.     End If
  14.     DoCmd.SetWarnings True
  15. End Sub
  16.  

hey thanx a lot that really worked.but instead of true i should be false.

thanx
Apr 26 '07 #6
MMcCarthy
14,534 Expert Mod 8TB
hey thanx a lot that really worked.but instead of true i should be false.

thanx
You're welcome.
Apr 26 '07 #7
pks00
280 Expert 100+
Hi Toral Shah, Im late in responding as usual!

Ok, Mary has given you one way, the other way to avoid those pesky message boxes is to use currentdb

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Enter()
  2.  
  3.     Dim strQry As String
  4.  
  5.     If IsNull(Me.Text0) = True Then
  6.         MsgBox "This record is blank. Please Enter something to save" _
  7. , vbInformation, "Invalid Action"
  8.     Else
  9.         strQry = "INSERT INTO [Table1] ([voc_no],[name]) Values ('" & Me!Text0 & "','" & Me!Text2 & "')"
  10.         currentdb.execute strQry, dbFailOnError
  11.     End If
  12. End Sub
  13.  

Can I make a recommendation and u rename your textbox fields to something more meaningful
Text0 and Text2 and default names supplied by Access. Its more better to use your own names eg txtVocNo and txtName
Apr 27 '07 #8

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

Similar topics

5
by: Jack | last post by:
Hi, I need to build a asp page where it would serve as a data entry record page as well as display page for records saved. This page should also allow editing of records that has been saved. ...
3
by: TheTenor | last post by:
I have a page with a graphic. I want to be able to define the graphics such that it is not saved when the viewer saves the page to his local drive. I'm trying to avoid having a seperate folder...
3
by: CSDunn | last post by:
Hello, I have an Access 2000 Project in which the data comes from a SQL Server 2000 database, and multiple users need to be able to see new records as each user adds records. The users also need...
1
by: Cillies | last post by:
Hello all, I was recently browsing the forum and remembered seeing a message relating to MS Access Bugs/Flaws. The thing is I cannot find that thread anymore, and so was wondering does anyone know...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
11
by: kaosyeti | last post by:
i have a form that records 9 fields into a table. on that form i have a 'done' button to close the form. right now, if the form is fully filled in, but you don't press 'enter' before you click...
4
by: John Kandell | last post by:
Hi, I posted this in the asp.net group, but didn't get a response. Maybe someone here can help me with this... --- Would someone be able to shed some light on what is the cost of saving a...
1
by: google | last post by:
I have a form with several subforms. Users enter the data, then on the parent there is a command button that runs code to generate a .pdf document from a report based on the data they are working...
3
by: Andy_Khosravi | last post by:
I'm having a problem with an entry form on one of my applications. It would appear that the save action is sometimes not working, and is generating no error when it fails. I'm hoping one of you may...
1
by: Cesar Zapata | last post by:
Hi, I have a a bound subform and what i'm trying to do is do check if some criteria applies before saving the record and trigger a macro. basically this is what I got. Date Received ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.