473,549 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Force .DefaultValue to be a string

74 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub OT_Test()
  2. If Forms!frmJobHourCostEmpName.TotalHours = 8 Then
  3. Me.OTJob.DefaultValue = True
  4. Me.BilledHours.DefaultValue = DLookup("OTApproval", "qryOTAllowance")
  5. Me.JobNumber.DefaultValue = DLookup(CStr("JobNo"), "qryOTAllowance")
  6. Me.BilledPercentage.DefaultValue = BilledHours / (8 + Nz(Forms!frmJobHourCostEmpName.OTHours, 0))
  7. End If
  8. 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
Expand|Select|Wrap|Line Numbers
  1. Dim JobNumberTemp as string
  2. JobNumberTemp = DLookup(CStr("JobNo"), "qryOTAllowance")
  3. Me.JobNumber.DefaultValue  = JobNumberTemp
  4.  
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.
Jun 3 '09 #1
25 5600
FishVal
2,653 Recognized Expert Specialist
Does it help to add text delimiters to the string assigned to DefaultValue property?

Regards,
Fish.
Jun 3 '09 #2
ChipR
1,287 Recognized Expert Top Contributor
Try
Expand|Select|Wrap|Line Numbers
  1. Me.JobNumber.DefaultValue  = """" & JobNumberTemp & """"
Jun 3 '09 #3
kstevens
74 New Member
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.
Jun 3 '09 #4
NeoPa
32,564 Recognized Expert Moderator MVP
Would it not work if the CStr() call were outside of the DLookup(), rather than within it?
Jun 4 '09 #5
missinglinq
3,532 Recognized Expert Specialist
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)>
Jun 4 '09 #6
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.
Expand|Select|Wrap|Line Numbers
  1. Me.JobNumber.DefaultValue = "'" & Me.JobNumberTemp & "'"
Jun 4 '09 #7
kstevens
74 New Member
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
Expand|Select|Wrap|Line Numbers
  1. """"
i almost always use
Expand|Select|Wrap|Line Numbers
  1. "'"
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
Expand|Select|Wrap|Line Numbers
  1. docmd.openreport "rptWhatEver",acnormal,,"stuff='" & text & "'" and anything else
  2.  
with multiple criteria, the confusion really begins.

and sometimes i even have to change that to
Expand|Select|Wrap|Line Numbers
  1. 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.
Jun 4 '09 #8
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.
Jun 4 '09 #9
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.

Expand|Select|Wrap|Line Numbers
  1. Dim strCriteria as String
  2. strCriteria = "[field1] = """ & variable & """"
  3. MsgBox strCriteria    'or Debug
  4. DLookup("field2", "table1", strCriteria)
Jun 4 '09 #10

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

Similar topics

0
3972
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...
2
26616
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 ? ...
1
1950
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!
3
4192
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.
1
1471
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(){}
5
1430
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
6
1906
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
3
1993
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 = ""
10
3271
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; }
0
7520
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, 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...
0
7450
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...
0
7720
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, 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. ...
0
7809
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 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...
0
6043
agi2029
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...
1
5368
isladogs
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...
0
5088
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...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
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

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.