473,387 Members | 1,876 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.

If WireBound = True Then Val(WirePrice) = ??

Hi Guys.. still trying to do this on my own but need help with below code.. im slowly getting there and loving it

(so wish I had discovered this stuff years ago, im actually enjoying my self while at work... :-) )

im not sure if ive got it queit right.. Basics:

I have a yes/no tick box [WireBound] once clicked
allows [WirePrice] box to calculate and to show:
[NumberOfBox] ( which user types in Number in "123" format)
times by (ExtraPricePerUnit) which is in another form, tbl or query


Private Sub WireBound_Click()
If WireBound = True Then Val(WirePrice) = Val(NumberOfWireBound) * Forms![frmExtras]!Val(ExtraPricePerUnit)
End Sub

now it dosnt show anything in the box [WirePrice]
Should i place code in [WirePrice] and code [WireBound] something like
If True then goto [WirePrice] or place it all in a modual as I have 8 more chek boxes for this to work with..

As Always thanks in anticipation

Sal
Sep 30 '09 #1
13 1430
pod
298 100+
I am not sure what is the problem without recreating your project. But my suggestions is verify what you get from those fields onChange or onClick then you can spot the culprit and work on a solution.

Expand|Select|Wrap|Line Numbers
  1. Private Sub WireBound_Click()
  2.     msgbox ("WireBound = " & WireBound)
  3.     msgbox ("WirePrice  = " & Val(WirePrice) )
  4.     msgbox ("ExtraPricePerUnit= " & Forms![frmExtras]!Val(ExtraPricePerUnit)
  5. End Sub
  6.  
Oct 6 '09 #2
A freind suggested this as my answer to the problem:

Private Sub RingBinder_Click()
Dim unitPrice As Double
Dim db As Database
Dim rs As Recordset
Dim sql As String

If Me.RingBinder.Value = True Then
Set db = CurrentDb
sql = "Select ExtraPricePerUnit from tblExtras where ExtrasDescription = ""Ring Binders"""
Set rs = db.OpenRecordset(sql)
unitPrice = rs.Fields(0).Value
Me!RingBinder = Me!NumberOfRingBindersBound.Value * unitPrice
Else
Me!RingBinder = 0
End If

End Sub


It appears to work fine (at moment) he says its Dynamic ???
Oct 6 '09 #3
pod
298 100+
The logic looks good
Oct 6 '09 #4
hmm except on using it in the other check boxes it messes up.. I have changed it in the right areas to go on other check boxes to manipulate other data but once clicked the original box increases in value ?? *bangs head on desk*

Ive attached in zip my first ever project trying to use vb access.. so please except it will be a tad erhm wrong in places..
any chance you can see where im going wrong ?? huh first stumbling block and im stuck how embaresing...
Attached Files
File Type: zip Printing.zip (120.6 KB, 54 views)
Oct 6 '09 #5
ah just found it user error I didnt replace all I should have (school boy error))
Oct 6 '09 #6
pod
298 100+
Good for you
I was about to post it :) ... always feels good to find it ourselves :)
Oct 6 '09 #7
Thanks and your right.. I keep trying never like the easy option as im trying to learn even if you do get some hints and tips doing it your self is much more rewarding at the end ..

now it aint working on others even when ive got the bits put in arghh *is still smiling* I will get there ...

any feed back on my access is always welcome if anything is glaringly bad, by the way..
Oct 6 '09 #8
pod
298 100+
one thing to remember when programming is : use a function when repetitive code is present. I see that you want to do basically the same function with the seven choices of parts.

try using a function with parameters. see below

Also you might want to call this sub from a change in the number of units field as well.... with condition of course


Expand|Select|Wrap|Line Numbers
  1. Private Sub RingBinder_Click()
  2.     Call setprice("Wire Binders", Me.WireBound, Me.NumberOfWireBound, Me.WirePrice)
  3. End Sub
  4. Private Sub WireBound_Click()
  5.     Call setprice("Ring Binders", Me.RingBinder, Me.NumberOfRingBinder, Me.RingBinderPrice)
  6. End Sub
  7. Private Sub DVD_Click()
  8.     Call setprice("DVD", Me.DVD, Me.NumberOfDVD, Me.DVDPrice)
  9. End Sub
  10.  
  11. Sub setprice(objDesc As String, objCheck As Control, objNumberOf As Control, objPrice As Control)
  12.  
  13.     Dim unitPrice As Double
  14.     Dim db As Database
  15.     Dim rs As Recordset
  16.     Dim sql As String
  17.  
  18.     If objCheck.Value = True Then
  19.         Set db = CurrentDb
  20.         sql = "Select ExtraPricePerUnit from tblExtras where ExtrasDescription = """ & objDesc & """"
  21.         Set rs = db.OpenRecordset(sql)
  22.         unitPrice = rs.Fields(0).Value
  23.         objPrice = objNumberOf.Value * unitPrice
  24.     Else
  25.         objPrice = 0
  26.     End If
  27.  
  28.  
  29. End Sub
Oct 6 '09 #9
Thanks I wil try that..

Question on line:

sql = "Select ExtraPricePerUnit from tblExtras where ExtrasDescription = """ & objDesc & """"

im guessing it knows to filter becouse of the code such as:

Private Sub WireBinder_Click()
Call setprice("Wire Binders", Me.WireBound, Me.NumberOfWireBound, Me.WirePrice)
End Sub

That allows the Sql """ & objDesc & """" find it ?

erhm if that made sense.. ?!
Oct 6 '09 #10
ok what im finding with both your way and the way I was doing it is: your way is tidier then me just repeating whole script (thanks for that note) but only the first two check boxes work and do as they should.. Ive messed around swapping code and position of boxes etc too but no matter what it dosnt seem to replecate the out come ie .. no price is shown what so ever in any of the otehr boxes as they do in the first two.. ?!
Oct 6 '09 #11
pod
298 100+
The "Sub setprice" is the main sub.
You still need to create "[Event Procedures]" for each checkboxes, (seven total including the three existing ones in the preceding code) the _Click events such as


Private Sub [fieldname]_Click()

and from each of those events, you must call the main sub with the right parameters, the ExtrasDescription (a string) and three control names; one checkbox and two textboxes
Oct 6 '09 #12
pod
298 100+
You are right, there was a flaw in my eventprocedures I had the WireBound calling changes for the RingBinders and vice versa ... Confusing part names :)

See code below for corrections

Private Sub WireBound_Click()
Call setprice("Wire Binders", Me.WireBound, Me.NumberOfWireBound, Me.WirePrice)
End Sub
Private Sub RingBinder_Click()
Call setprice("Ring Binders", Me.RingBinder, Me.NumberOfRingBinder, Me.RingBinderPrice)
End Sub
Oct 6 '09 #13
yes I changed them back over *at least I think* damn im enjoying this stuff thanks for your help...
Oct 7 '09 #14

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

Similar topics

46
by: Scott Chapman | last post by:
There seems to be an inconsistency here: Python 2.3.2 (#1, Oct 3 2003, 19:04:58) on linux2 >>> 1 == True True >>> 3 == True False >>> if 1: print "true" ....
3
by: drs | last post by:
I just upgraded my Python install, and for the first time have True and False rather than 1 and 0. I was playing around at the command line to test how they work (for instance, "if 9:" and "if...
35
by: Steven Bethard | last post by:
I have lists containing values that are all either True, False or None, e.g.: etc. For a given list: * If all values are None, the function should return None.
36
by: Remi Villatel | last post by:
Hi there, There is always a "nice" way to do things in Python but this time I can't find one. What I'm trying to achieve is a conditionnal loop of which the condition test would be done at...
14
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a...
48
by: Skybuck Flying | last post by:
Hi, I came across this C code which I wanted to understand etc it looked like this: if (-1) etc It made me wonder what the result would be... true or false ? In C and Delphi
30
by: Jason | last post by:
I am fairly new to ASP--I have been using it about 2 months. I did these tests (below), and it doesn't make sense to me. False is equal to 0, and that's fine. True should be equal to 1, but it's...
90
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
40
by: nufuhsus | last post by:
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...

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.