borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Lining up colums and rows)Next Topic (timer?) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : MS Access Default Value
Poster Message
CLIPER
Level: Big Cheese

Registered: 26-07-2005
Posts: 27

icon MS Access Default Value

Hi, I just want to ask what should be the Code to have a Computed Value in Access..

I've tried all samples in Access Help and still I have an error.

Here..

From Table1, there are 4 columns: City, Barangay, Desc and CompVal

City = 01 Barangay=01... etc.

Now, CompVal should be 001

Now, I use this method...
=[City]+[Barangay]


Can anyone?thanks..

____________________________
CLIPER

12-09-2005 at 11:16 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
xtramac
Level: Professor


Registered: 28-08-2005
Posts: 89
icon Re: MS Access Default Value

hello cliper,

i think your question is very confusing...

be more specific....

based on what you have here.. [city] + [barangay] is not acceptable since both are texts and there's no logic in it..

see you next post... i hope i can help you..


[Edited by xtramac on 16-09-2005 at 09:24 AM GMT]

16-09-2005 at 01:12 AM
View Profile Send Email to User Show All Posts | Quote Reply
CLIPER
Level: Big Cheese

Registered: 26-07-2005
Posts: 27
icon Re: MS Access Default Value

ok,  let us assume that we have 3 fields (columns) in table maindb

1st field: City
2nd field: Barangay
3rd field: String

Now, in the field City we have a value of 01 and in the Barangay field we have a value of 002 now.. I just need to merge that numbers using the computed value of default value in the Access DB.

So the result should be 01002...

I use =[City] & [Barangay] and its not working...

____________________________
CLIPER

16-09-2005 at 04:21 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
CLIPER
Level: Big Cheese

Registered: 26-07-2005
Posts: 27
icon Re: MS Access Default Value

I hope someone could answer this problem.. I am waiting for a reply. thanks. If you want further info please pm me or post  a reply. thanks.

____________________________
CLIPER

12-10-2005 at 05:06 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
TJ_01
Level: VB Lord


Registered: 24-08-2005
Posts: 320
icon Re: MS Access Default Value

ok. Try this one:
rs.Open "Select * from TblName where city = '01'", CON, adOpenKeyset, adLockOptimistic
  if rs.EOF = False then
   Label3.Caption = rs.Fields("City") & rs.Fields("Brgy")
  else
   exit sub
  end if



HTH..







[Edited by TJ_01 on 12-10-2005 at 05:30 AM GMT]

____________________________
Im JAMES  

12-10-2005 at 05:18 AM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: MS Access Default Value

Hello
I tried the following in MSAccess 97, and it works

"SELECT Questions.AnswerOption1, Questions.AnswerOption2, [AnswerOption1] & [AnswerOption2] AS Sample
FROM Questions;"

I believe the trick is using the AS keyword to assign a name to the computed field.
I am also aware the syntax depends on the engine you use, and it could be different among MSAccess SQL, TSQL or other SQL dialects. For instance, MySql uses the CONCAT funcion to concatenate two strings.

Hope it helps

____________________________
Real Programmer can count up to 1024 on his fingers

12-10-2005 at 06:06 AM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 536
icon Re: MS Access Default Value

Ah !
Would I be right in thinking that you are not trying to do this in the VBA Code window but are trying to put this calculation into the "Default Value" Property of the Field in the Table Design ? If that is the case you cannot do it - the value for this property must be a String, you cannot put a formula unless it uses one of the built in Functions (click on the elipses to open the Expression Builder to see what these are)

BUT - you CAN do it on a Form, so if you put your formula into the "Control Source" Property of a Text Box Control then it will calculate it for you. The downside to that is that it will not be saved to the database table, it will only display on the Form, the upside of course is that your database will be smaller as you would not be saving the third field.


[Edited by GeoffS on 12-10-2005 at 01:35 PM GMT]

____________________________
multi-tasking - the ability to hang more than one app. at the same time.

12-10-2005 at 01:27 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : MS Access Default Value
Previous Topic (Lining up colums and rows)Next Topic (timer?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder