473,473 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Still stuck! - Getting data from a form field to input data to table

blyxx86
256 Contributor
I'm having a difficult time here, and am not sure what needs to be done to get this working.

I have a textbox on a form who's control source is
Expand|Select|Wrap|Line Numbers
  1. =IIf(([cboScanner]="Pass" And [cboDisplay]="Pass" And [cboKeypad]="Pass" And [cboRadio]="Pass" And [cboStructural]="Pass"),"Pass","Fail")
  2.  
I want the value of this field after it computes to be placed into the field "Overall" on my database.

So far this code has not worked, it input a new record into the table, but did not update the current record I was actually creating with my form:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. strSQL = "INSERT INTO QC(Overall) Values([cboOverall])"
  3. DoCmd.RunSQL (strSQL)
  4. End Sub
  5.  

This code did not do anything at all ([ID] is bound to the field ID on my table]
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboOverall_AfterUpdate()
  2. Dim strSQL As String
  3. strSQL = "UPDATE QC SET Overall='" & [cboOverall] & "' WHERE ID =" & [ID] & ";"
  4. DoCmd.RunSQL (strSQL)
  5. End Sub
  6.  
Any idea on how to do this?
Nov 29 '06 #1
14 1647
MMcCarthy
14,534 Recognized Expert Moderator MVP
I'm having a difficult time here, and am not sure what needs to be done to get this working.

I have a textbox on a form who's control source is
Expand|Select|Wrap|Line Numbers
  1. =IIf(([cboScanner]="Pass" And [cboDisplay]="Pass" And [cboKeypad]="Pass" And [cboRadio]="Pass" And [cboStructural]="Pass"),"Pass","Fail")
  2.  
I want the value of this field after it computes to be placed into the field "Overall" on my database.
Remove the statement from the control source.

Set the Control Source to the field Overall.

You could put the statement in the default value but I don' think that will work. You will have to put the statement in code similar to the below in the before update event of the control [Overall].

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Overall_BeforeUpdate()
  3.  
  4.    Me.Overall = IIf(([cboScanner]="Pass" And [cboDisplay]="Pass" & _
  5.       " And [cboKeypad]="Pass" And [cboRadio]="Pass" & _
  6.       " And [cboStructural]="Pass"),"Pass","Fail")
  7.  
  8. End Sub
  9.  
Nov 30 '06 #2
blyxx86
256 Contributor
Remove the statement from the control source.

Set the Control Source to the field Overall.

You could put the statement in the default value but I don' think that will work. You will have to put the statement in code similar to the below in the before update event of the control [Overall].

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Overall_BeforeUpdate()
  3.  
  4.    Me.Overall = IIf(([cboScanner]="Pass" And [cboDisplay]="Pass" & _
  5.       " And [cboKeypad]="Pass" And [cboRadio]="Pass" & _
  6.       " And [cboStructural]="Pass"),"Pass","Fail")
  7.  
  8. End Sub
  9.  
Bah! I thought about that yesterday and thought it wouldn't work.
I have tried with the default value, but it didn't work, you were correct.
I will do this. Thank you.
Nov 30 '06 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Bah! I thought about that yesterday and thought it wouldn't work.
I have tried with the default value, but it didn't work, you were correct.
I will do this. Thank you.
You're welcome.

Let me know if it works ok.

Mary
Nov 30 '06 #4
blyxx86
256 Contributor
You're welcome.

Let me know if it works ok.

Mary
Still no.

I am messing with the code now, i'm not sure if it's just not formatted properly or not. I am retrying a few things and rewriting it a bit.

I'll let you know in a minute.
Nov 30 '06 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Still no.

I am messing with the code now, i'm not sure if it's just not formatted properly or not. I am retrying a few things and rewriting it a bit.

I'll let you know in a minute.
Try putting the code in the after update event of the last combo box to be changed.
Nov 30 '06 #6
blyxx86
256 Contributor
Try putting the code in the after update event of the last combo box to be changed.
Perhaps I can put it on the button I press at the end of the form? In the OnClick function?

The code is coming up with an error..

"Syntax error."

The entire thing is red and is all selected when I try to compile the code.

I still don't understand how VBA is meant to be formatted and whether or not things use quotes, parenthesis, single quotes, brackets, ampersands, etc...

Ok.. it comes up with a more specific error when I forgot to change the name of the control to meet my actual control.

expected: )

On the second line, it selects Pass and gives the error. No idea.
Nov 30 '06 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
Sorry that's my fault. Try this and put it in the click event, sounds like a good idea.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Me.Overall = IIf(([cboScanner]="Pass" And [cboDisplay]="Pass" & _
  3.        And [cboKeypad]="Pass" And [cboRadio]="Pass" & _
  4.        And [cboStructural]="Pass"),"Pass","Fail")
  5.  
Nov 30 '06 #8
blyxx86
256 Contributor
Sorry that's my fault. Try this and put it in the click event, sounds like a good idea.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Me.Overall = IIf(([cboScanner]="Pass" And [cboDisplay]="Pass" & _
  3.        And [cboKeypad]="Pass" And [cboRadio]="Pass" & _
  4.        And [cboStructural]="Pass"),"Pass","Fail")
  5.  
I modified it to just be on one line and it seemed to work, I only kinda understand how it pieces all of the " and ' and () and []... Eventually..

I'm hoping tonight I'll be able to sit down and go through and do some basic reading on how they are pieced together, because that is the only thing really confusing me. How it is all put together so that VBA can actually use what I type as valid.

I have a question.. When do I determine whether to type something like...

Me.Overall.Text/Value or to just leave it as Me.Overall ? I know that I can change the properties of the field using Me.Overall.DefaultValue/etc, but what is "text" and "value" ?
Nov 30 '06 #9
MMcCarthy
14,534 Recognized Expert Moderator MVP
IIf(<Expression>, <Value if true>, <Value if False>) is a function.

The second set of brackets
i.e. ([cboScanner]="Pass" And [cboDisplay]="Pass" And [cboKeypad]="Pass" And [cboRadio]="Pass" And [cboStructural]="Pass")
is used to tidy up the expression.

[cboKeypad] square brackets are used around any field or table names. They can also be used around any other object name like controls, forms, queries, etc.

"Pass" is the value if the expression is true, quotation marks indicate a string value
"Fail" is the value if the expression is false, quotation marks indicate a string value

I used the & _ to tell the code that the statement wasn't finished but continued on the next line.

Mary
Nov 30 '06 #10
blyxx86
256 Contributor
IIf(<Expression>, <Value if true>, <Value if False>) is a function.

The second set of brackets
i.e. ([cboScanner]="Pass" And [cboDisplay]="Pass" And [cboKeypad]="Pass" And [cboRadio]="Pass" And [cboStructural]="Pass")
is used to tidy up the expression.

[cboKeypad] square brackets are used around any field or table names. They can also be used around any other object name like controls, forms, queries, etc.

"Pass" is the value if the expression is true, quotation marks indicate a string value
"Fail" is the value if the expression is false, quotation marks indicate a string value

I used the & _ to tell the code that the statement wasn't finished but continued on the next line.

Mary
The brackets are used only inside of a function though, correct?

String values, do they output as text? I know I had to do quite a bit of tweaking to get a DefaultValue to be changed via VBA, because the default value needs quotes within quotes and VBA wasn't liking that.

So you have to create something that is...
Const cQuote = """"

Yet """" returns only a single " to the function. How does it return only one? I see two sets. Or is it just a mystery of code. The other one is lost to heat or something (physics joke).
Nov 30 '06 #11
MMcCarthy
14,534 Recognized Expert Moderator MVP
The brackets are used only inside of a function though, correct?
The round brackets, yes.

String values, do they output as text? I know I had to do quite a bit of tweaking to get a DefaultValue to be changed via VBA, because the default value needs quotes within quotes and VBA wasn't liking that.
For quotes within quotes you always use single quotes within double quotes. You don't need the const.
Nov 30 '06 #12
NeoPa
32,556 Recognized Expert Moderator MVP
The brackets are used only inside of a function though, correct?

String values, do they output as text? I know I had to do quite a bit of tweaking to get a DefaultValue to be changed via VBA, because the default value needs quotes within quotes and VBA wasn't liking that.

So you have to create something that is...
Const cQuote = """"

Yet """" returns only a single " to the function. How does it return only one? I see two sets. Or is it just a mystery of code. The other one is lost to heat or something (physics joke).
Quotes are always confusing.
Quotes normally toggle between 'Treat followng data as a literal string' and 'Stop treating following chars as a literal string'.
But consider a string "Please enter dbl-qoutes (") here". When it hits the second ", within (), it will interpret that as the end of the string literal which is not what we want.
There is a standard way around that, which is to double-up quotes contained in a string. Thus the string would actually be referred to in code as "Please enter dbl-qoutes ("") here".
A string, then, which is just a single " character, would be written in code as """".
Expand|Select|Wrap|Line Numbers
  1. strSQL = """"
  2. Debug.Print "Result = "; strSQL
  3. Result = "
Dec 1 '06 #13
blyxx86
256 Contributor
Quotes are always confusing.
Quotes normally toggle between 'Treat followng data as a literal string' and 'Stop treating following chars as a literal string'.
But consider a string "Please enter dbl-qoutes (") here". When it hits the second ", within (), it will interpret that as the end of the string literal which is not what we want.
There is a standard way around that, which is to double-up quotes contained in a string. Thus the string would actually be referred to in code as "Please enter dbl-qoutes ("") here".
A string, then, which is just a single " character, would be written in code as """".
Expand|Select|Wrap|Line Numbers
  1. strSQL = """"
  2. Debug.Print "Result = "; strSQL
  3. Result = "
Could you explain that last little piece of code to me? Now there is a semicolon involved and it didn't show up in the output. It's like learning grammar for a new language, that is very disimilar to my current language (English) and also, where would you place that code to see the results you entered?

I now know I could do a msgbox command to show the "strsql" but would still like to be able to see it within VBA. You aksed me in the other thread if I knew about breaks and watches and such. I do not really have any idea. I did put a watch in on one expression, but I don't think it did anything.
Dec 1 '06 #14
NeoPa
32,556 Recognized Expert Moderator MVP
Semi-colon ( ; ) in a Print steam denotes that the following item should follow on without any break.
Expand|Select|Wrap|Line Numbers
  1. Debug.Print """"
  2. Produces the simple result :
  3. "
"Result = " resolves to
Result =
then """" resolves to
"
Could have been written as
Expand|Select|Wrap|Line Numbers
  1. strSQL = """"
  2. Debug.Print "Result = " & strSQL
  3. Result = "
Dec 1 '06 #15

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

Similar topics

18
by: Phill Long | last post by:
this is the the code, now here is the final result.... I get one combo box and one tex box come up, but they are empty... DAMN!!! Any ideas on what Im doing wrong please.. Thanks Again <?php...
8
by: Michael C | last post by:
Hi all, I'm still having problems with VS.NET 2003 running on my XP machine. I finally decided I might as well uninstall completely and reinstall from scratch. But lo and behold it won't let...
26
by: _R | last post by:
Given that VS2005 has made an effort to clean up the syntax of VC++ (in C++/CLI), is there any future plans to do away with function protos, ala C#/VB? What are they needed for these days?
7
by: Tony Johansson | last post by:
Hello! If you want to create an GUI application using a tool in visual studion 6.0 you are forced to use MFC. I just want to know about the developing GUI application in C++ visual studio...
0
by: RSB | last post by:
Hi Everyone, I am still Stuck with this issue. I been using my local machine as develpoment machine and once i moved the Stuff to a Server ( i used xCopy) i cannot not view the Pages. When i...
6
by: darrel | last post by:
I've asked this a few times and gotten answers, but I'm still missing a piece of the puzzle. Here's what I have: - page.aspx - title tag - usercontrol.aspx - usercontrol.aspx.vb
3
by: mensanator | last post by:
## Holy Mother of Pearl! ## ## >>> for i in range(10): ## for j in range(10): ## print '%4d' % (gmpy.mpz(i)*gmpy.mpz(j)), ## print ## ## ## ...
21
by: AsheeG87 | last post by:
Hey Everyone~ I'm still a C++ Rookie so please bear with me on this. I'm doing a temperature conversion program with prototype functions. Basicly, I was wondering if some of you would take a look...
4
by: =?Utf-8?B?TWF1cg==?= | last post by:
My cd is stuck in the drive. I can open the drawer O K but the c d will not come out Help me please -- Maur
13
by: canabatz | last post by:
i got for example this result from data base: user1 user1 user1 user2 user2 user1 user1
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...
1
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...
0
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...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.