I have a sub to determine if overtime has come into play yet on a certain job. If (preapproved) overtime has started then the next (subform) record can automatically be populated from a query checking the overtime allowance. Here is the code. - Private Sub OT_Test()
-
If Forms!frmJobHourCostEmpName.TotalHours = 8 Then
-
Me.OTJob.DefaultValue = True
-
Me.BilledHours.DefaultValue = DLookup("OTApproval", "qryOTAllowance")
-
Me.JobNumber.DefaultValue = DLookup(CStr("JobNo"), "qryOTAllowance")
-
Me.BilledPercentage.DefaultValue = BilledHours / (8 + Nz(Forms!frmJobHourCostEmpName.OTHours, 0))
-
End If
-
End Sub
The issue is that Job Numbers are in a format of:
Example: "12345-1" or "12345-2" or "65487-1"...ok you get it.
you may have noticed the DLookup( CStr("JobNo"),"qryOTAllowanc e")
The actual field in the query is JobNo: Cstr(Jobnumber)
I even tried - Dim JobNumberTemp as string
-
JobNumberTemp = DLookup(CStr("JobNo"), "qryOTAllowance")
-
Me.JobNumber.DefaultValue = JobNumberTemp
-
In hoping that the "JobNumber.Defa ultValue" would remain a string ("12345-2") instead of a math problem (12345-2 = 12343) because all that i can get to display is "12343" I noticed that if i dont use defaultvalue, i get the actual string, but obviously on the wrong record (the current record, instead of the next record)
Does anybody have any ideas of how to accomplish this? Its driving me nuts. As always..... Thanks for any help.
25 5600 FishVal 2,653
Recognized Expert Specialist
Does it help to add text delimiters to the string assigned to DefaultValue property?
Regards,
Fish.
ChipR 1,287
Recognized Expert Top Contributor
Try - Me.JobNumber.DefaultValue = """" & JobNumberTemp & """"
Thanks ChipR and FishVal i never tried it, because originally i thinking about 1 set of quotes which would have been a literal sting but i never thought about """" & so thanks. It worked great.
NeoPa 32,564
Recognized Expert Moderator MVP
Would it not work if the CStr() call were outside of the DLookup(), rather than within it?
I'm really confused here! If the values in this field are in a format of:
"12345-1" or "12345-2" or "65487-1"
then the field is defined as Text. You cannot enter these values in a field that is defined as a Number datatype.Why do you need to use CStr()? Using Chip's suggestion alone should do it.
Linq ;0)> NeoPa 32,564
Recognized Expert Moderator MVP
Quite right. I skimmed over the penultimate paragraph in the OP too quickly it seems.
In that case Chip is indeed on the ball (again).
I would do it very slightly differently for reasons explained in Quotes (') and Double-Quotes (") - Where and When to use them. - Me.JobNumber.DefaultValue = "'" & Me.JobNumberTemp & "'"
I did use Chips solution and it did work. Originally the query was doing the math problem instead of correctly reporting it as text. Then (only when i set .defaultvalue = tempjobnumber) it was still doing the math. I havent had a chance to use NeoPa's advice because once it worked.... I stopped, lol. OFF TOPIC Can you hijack your own thread? :)
I never usually use
i almost always use
although i know it will get me in trouble one day ( actually it already has with an emplyees last name - O'Bryant). I REALLY struggle when it comes to text delimeters, i have read the tutorial on here about it, but it doesnt really help me.....(well it does with individual fields, but when i try to do - docmd.openreport "rptWhatEver",acnormal,,"stuff='" & text & "'" and anything else
-
with multiple criteria, the confusion really begins.
and sometimes i even have to change that to - docmd.openreport "rptWhatEver",acnormal,,"stuff=" & "'" & text & "'" and anything else
And i havenet really quite figured out why... i tend to use the first one most of the time, now that i think about it, iam not really sure which one ends up giving me the problems.
NeoPa 32,564
Recognized Expert Moderator MVP
Such problems can occur either way in fact.
EG. {O'Brien}
{4" by 2" plank}.
" is a sign for Inches if you weren't aware of that.
Doubling-up quotes in the data is generally a way to get past this.
The correct (standard) character for quotes in SQL strings is ('). Access uses (") by default instead (M$ were stupid enough to think that this would simplify matters rather than the fairly predictable result of confusing people greatly). In Access either will work though (at least until ANSI-92 becomes the default, which is unlikely to be far away).
To program such problems properly, it is advisable to pass any such references through a filter function so that any such quotes get doubled for you automatically if they occur.
I hope this helps and clarifies things for you a bit.
ChipR 1,287
Recognized Expert Top Contributor
The best way to figure this out is to use an intermediate variable so that you can check the value of the string. This way, you will quickly see where you made a mistake. - Dim strCriteria as String
-
strCriteria = "[field1] = """ & variable & """"
-
MsgBox strCriteria 'or Debug
-
DLookup("field2", "table1", strCriteria)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Craig Schneider |
last post by:
// Is there any way to override the XML Serialization of the following
SimpleClass
// to turn off the DefaultValue of a boolean? Sure, I can override
the DefaultValue from
// true to false, but that is not what I want/need. I really need to
just override the fact
// that the developer ever supplied a DefaultValue. Setting an
override...
|
by: Andreas Palm |
last post by:
I have a dataset that has DBNull in certain columns, now when I write
out this one to XML, I only get the columns as elements that do have
data in it. However I do need also the empty colums as empty elements
in the XML. How to do that ?
I don't understand why there is no simple option to specify the output
format, or did I miss something ?
...
|
by: Mark |
last post by:
How do I write the following code to set the default value?
Me!xNum.DefaultValue =
Me!XCurrency.DefaultValue =
Me!XDate.DefaultValue =
Me!XString.DefaultValue =
Can I just put all the lines of code in the Form's AfterUpdate event?
Thanks!
|
by: Bram Vandendriesschen |
last post by:
Hi,
anyone an idea how to get DefaultValue's working for
String properties in managed C++.
I wrote a component in managed C++ which I plan to consume
in C#. Now the IDE keeps inserting null-assignments for
the string properties, while I've specified that NULL is
the default value. Other types work well.
thanks in advance,
Bram.
|
by: RR |
last post by:
Hi,
I want to set the defaultvalue of a property in a class.
I know this is possible by the DefaultValue Attribute like this:
public class Test
{
public Test(){}
| |
by: schneider |
last post by:
Hello,
Have an issue with a property using the DefaultValue(True) attribute.
Imports System.ComponentModel
Public Class Class1
Private m_testValue As Boolean
|
by: Meelis Lilbok |
last post by:
Hi
Why does property default value not work?
When i start my application and dont set value from properties window
the value is always "nothing". Whats the point off DefualtValue then?
Regards;
Meelis
|
by: MLH |
last post by:
On frmVehicleEntryForm...
I wanted to change the DefaultValue property
of one of my textbox controls on a form from within
code. I wanted the setting to be no setting - as if
nothing had ever been entered there. First, I used
Me!TowFee.DefaultValue = Null
That returned an error, so I used
Me!TowFee.DefaultValue = ""
|
by: tony |
last post by:
Hello!!
I have some demo programs written in C# and they have this construction
"" see below.
I haven't seen this before so what does it mean ?
public bool ShowDropDownButtons
{
get { return showDropDownButtons; }
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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...
|
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...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |