Hi,
I have got an ADD button with the following code: Private Sub addrec_Click()
On Error GoTo Err_addrec_Click
DoCmd.GoToRecord , , acNewRec
Exit_addrec_Click:
Exit Sub
Err_addrec_Click:
MsgBox Err.Description
Resume Exit_addrec_Click
End Sub
and i have some validations through the following code: Private Sub Form_BeforeUpdate(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.username) Or Me.username = "" Then
blnValidate = True
strValidate = strValidate & "Username" & vbCrLf
End If
If IsNull(Me.number) 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
74 6111 NeoPa 32,511
Expert Mod 16PB
Sorry Beany, should have said more clearly.
Can you post what's in the Debug window for the Debug.Print line too please.
You only need the & _ when continuing on the next line.
[PHP]
Private Sub addrec_Click()
Dim strSQL As String
strSQL = "INSERT INTO tab_main (username, cost_centre, number, phone_model, imei, puk_code, sim_no, date_issued, notes, tariff, call_int, roam) VALUES ('" & Me.username & "','" & Me.cost_centre & "','" & Me.number & "','" & Me.phone_model & "','" & Me.imei & "','" & Me.puk_code & "','" & Me.sim_no & "',#" & Me.date_issued & "#,'" & Me.notes & "','" & Me.tariff & "'," & Me.call_int & "," & Me.roam & ")"
Debug.Print strSQL
DoCmd.RunSQL strSQL
End Sub[/PHP]
Sorry Neo
here we are:
[PHP]INSERT INTO tab_main (username, cost_centre, number, phone_model, imei, puk_code, sim_no, date_issued, notes, tariff, call_int, roam) VALUES ('Test','London','07777777777','Ericsson R310S','12121212','2323232323','3434343434343',#01/03/2004#,'help me','free',0,0);[/PHP]
Mary, there is no &_? (or shall i go to specsavers??) :)
thanks peeps
Just copy and paste my code exactly as it is in the last post and then tell me what is in the immediate pane result. There is something wrong with the date you put in the last post is this just a typing error.
Mary
ive copied your code and got the following in the immediate pane:
[PHP]INSERT INTO tab_main (username, cost_centre, number, phone_model, imei, puk_code, sim_no, date_issued, notes, tariff, call_int, roam) VALUES ('Hello','Leeds','121212121','Blackberry 7100v','1213344444','444455445443','334434434',#01/03/2006#,'asasas','monthly',0,0)[/PHP]
There doesn't appear to be any mistakes in the code. I can't understand why it's not working for you.
The only other thing I can suggest is putting square brackets around the table name and each of the field names but that shouldn't make any difference unless there is aVBA protected word in there somewhere. -
INSERT INTO [tab_main] ([username], [cost_centre], [number], [phone_model], [imei], [puk_code], [sim_no], [date_issued], [notes], [tariff], [call_int], [roam]) VALUES ........etc.
-
Mary
ive got a userID field in my table tab_main..............
but i dont have a field for that in my form.........
that doesnt make a difference does it?
ive got a userID field in my table tab_main..............
but i dont have a field for that in my form.........
that doesnt make a difference does it?
That's fine as long as userID is an autonumber. Did the square brackets make any difference?
Mary
some good news the square brackets adds the details into the table......
but before it does add i get the message .... You are about to append 1 row(s). Once you click Yes, you can't use the Undo command to reverse the changes.
Are you sure you want to append the selected rows? YES NO
Why is this?????????????????????
NeoPa 32,511
Expert Mod 16PB
That's because it's working now.
To hide that message put - DoCmd.SetWarnings = False
but remember to set it back to True again at the end of your running code.
The undo command is used for forms to undo the user entry before a record is saved. Once you append a record to the table you can't undo it.
Mary
some good news the square brackets adds the details into the table......
but before it does add i get the message .... You are about to append 1 row(s). Once you click Yes, you can't use the Undo command to reverse the changes.
Are you sure you want to append the selected rows? YES NO
Why is this?????????????????????
That's because it's working now.
To hide that message put - DoCmd.SetWarnings = False
but remember to set it back to True again at the end of your running code.
Hi Ade
I'm supposed to be working and doing anything to avoid it. HELP!!
Mary
ive inserted the DoCmd.SetWarnings = False into the code...
is that the right place?
[PHP]Private Sub addrec_Click()
Dim strSQL As String
strSQL = "INSERT INTO tab_main ([username], [cost_centre], [number], [phone_model], [imei], [puk_code], [sim_no], [date_issued], [notes], [tariff], [call_int], [roam]) VALUES ('" & Me.username & "','" & Me.cost_centre & "','" & Me.number & "','" & Me.phone_model & "','" & Me.imei & "','" & Me.puk_code & "','" & Me.sim_no & "',#" & Me.date_issued & "#,'" & Me.notes & "','" & Me.tariff & "'," & Me.call_int & "," & Me.roam & ")"
''Debug.Print strSQL
DoCmd.RunSQL strSQL
DoCmd.SetWarnings = False
End Sub[/PHP]
im getting a message sayin Compile Error:
Argument not optional
and what did you mean when......... put it back to true when running the code?
NeoPa 32,511
Expert Mod 16PB
ive inserted the DoCmd.SetWarnings = False into the code...
is that the right place?
[PHP]Private Sub addrec_Click()
Dim strSQL As String
strSQL = "INSERT INTO tab_main ([username], [cost_centre], [number], [phone_model], [imei], [puk_code], [sim_no], [date_issued], [notes], [tariff], [call_int], [roam]) VALUES ('" & Me.username & "','" & Me.cost_centre & "','" & Me.number & "','" & Me.phone_model & "','" & Me.imei & "','" & Me.puk_code & "','" & Me.sim_no & "',#" & Me.date_issued & "#,'" & Me.notes & "','" & Me.tariff & "'," & Me.call_int & "," & Me.roam & ")"
''Debug.Print strSQL
DoCmd.RunSQL strSQL
DoCmd.SetWarnings = False
End Sub[/PHP]
im getting a message sayin Compile Error:
Argument not optional
and what did you mean when......... put it back to true when running the code?
Oh BEANY!
What I meant was - Private Sub addrec_Click()
-
Dim strSQL As String
-
strSQL = "INSERT INTO tab_main ([username], [cost_centre], [number], [phone_model], [imei], [puk_code], [sim_no], [date_issued], [notes], [tariff], [call_int], [roam]) VALUES ('" & Me.username & "','" & Me.cost_centre & "','" & Me.number & "','" & Me.phone_model & "','" & Me.imei & "','" & Me.puk_code & "','" & Me.sim_no & "',#" & Me.date_issued & "#,'" & Me.notes & "','" & Me.tariff & "'," & Me.call_int & "," & Me.roam & ")"
-
''Debug.Print strSQL
-
-
DoCmd.SetWarnings = False
-
DoCmd.RunSQL strSQL
-
DoCmd.SetWarnings = True
-
End Sub
Now, what I'm trying to encourage you to do is to sit and think about your problems first.
We can help, but you need to try first - otherwise we are just a crutch for you, and you will never learn to walk. We want you to learn from what we put in here, not just use the code. You understand?
Mary,
I'll try to keep things up-to-date but I'm not checking all the time as my head's buried (No - not there! In some code.)
I should be able to respond to most though in time.
You focus on your work.
-Ade.
Firstly, you don't use the = sign as the False is a parameter.
Think of it logically. You are turning the warnings off before you run the code and back on after you run it so ....
[PHP]
Private Sub addrec_Click()
Dim strSQL As String
DoCmd.SetWarnings False
strSQL = "INSERT INTO tab_main ([username], [cost_centre], [number], [phone_model], [imei], [puk_code], [sim_no], [date_issued], [notes], [tariff], [call_int], [roam]) VALUES ('" & Me.username & "','" & Me.cost_centre & "','" & Me.number & "','" & Me.phone_model & "','" & Me.imei & "','" & Me.puk_code & "','" & Me.sim_no & "',#" & Me.date_issued & "#,'" & Me.notes & "','" & Me.tariff & "'," & Me.call_int & "," & Me.roam & ")"
''Debug.Print strSQL
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End Sub
[/PHP]
Mary
Neo, im still getting the same error???? even with the above code
Mary your way worked!!!!
amazing.....thank you and Neo..................
how did you lot learn this much?
any recommendations for beginners?
NeoPa 32,511
Expert Mod 16PB
Firstly, you don't use the = sign as the False is a parameter.
Think of it logically. You are turning the warnings off before you run the code and back on after you run it so ....
That was my bad Mary.
That's how I did it in an earlier post :(.
Beany was just following my lead - oops.
Neo, im still getting the same error???? even with the above code
Beany
Did you try my code.
BTW, Adrian I'm not saying you're wrong :) but you have had great fun telling me how many mistakes I made yesterday when I had a hangover that I couldn't resist pointing out one of your rare ones.
Mary
NeoPa 32,511
Expert Mod 16PB
Beany
Did you try my code.
BTW, Adrian I'm not saying you're wrong :) but you have had great fun telling me how many mistakes I made yesterday when I had a hangover that I couldn't resist pointing out one of your rare ones.
Mary
Fun it was - and is the other way around too.
Heard a great one this morning from an Ausi radio station...
Q. What's the difference between a Pom and a Jumbo Jet's engine?
A. The engine stops whining when it reaches Australia.
Cracked me up (the b*stards).
thats funny................
Fun it was - and is the other way around too.
Heard a great one this morning from an Ausi radio station...
Q. What's the difference between a Pom and a Jumbo Jet's engine?
A. The engine stops whining when it reaches Australia.
Cracked me up (the b*stards).
Have to tell Killer that one.
Since I'm not a Pom I can laugh wholeheartedly. :)
Mary
Mary your way worked!!!!
amazing.....thank you and Neo..................
how did you lot learn this much?
any recommendations for beginners?
Hi Beany
Unfortunately, there is no easy way to pick this stuff up as it comes from years of experience learning the hard way how these things work.
The best recommendation I can give you is that when you have a question on how to do something try to find answers already posted on the web in forums like this one and then try to follow for yourself what's going on and why.
When you run into trouble we'll be here but you will learn much more if you try to figure it out for yourself by playing around with the code and see what works and what doesn't.
Mary
NeoPa 32,511
Expert Mod 16PB
Beany,
Pay close attention to what Mary says. She knows what she's talking about.
Many people forget to use the Help system too.
You can get a long way by using what's included in the software as Help.
I've learned most of what I know by playing around (I wish! - I mean within Access) with things and reading up on the correct syntax from Help.
cool.......
will bear that in mind...........thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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. ...
|
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...
|
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...
|
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...
|
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...
|
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 ...
|
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...
|
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...
|
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...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
| |