A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Text value type is calculated on INSERT



 
 
Thread Tools Display Modes
  #1  
Old March 21st, 2010, 09:02 PM posted to microsoft.public.access.gettingstarted
IgorM[_2_]
external usenet poster
 
Posts: 32
Default Text value type is calculated on INSERT

Hi

I think this is the right group for my question.
I have a macro in Excel VBA that inserts data into Access accdba database.
The code snippet that inserts the data is:

Public Function InsertPhotoMapNumbers(ByRef miMaxMapNo As Integer, ByRef
miApplicationYear As Integer) As Long
Dim msMapNo As String

'Some code here
msMapNo = CStr(miMapNo) + "/" + CStr(miMaxMapNo)
mobjCommand.CommandText = "INSERT INTO tblMaps(PhotoMapNo, ApplicationYear)
VALUES (" & msMapNo & "," & miApplicationYear & ")"

'Execute the SQL statement.
mobjCommand.Execute RecordsAffected:=mlRecordsAffected, _
Options:=adCmdText Or adExecuteNoRecords

'Some more code here
End Function


The data in PhotoMapNo column of the tblMaps table should look like:
"255/758", "256/758" etc. The PhotoMapNo column is of text type.
Unfortunately at some point the two values are treated as values and
calculated (divided) so they look like 0,33641, etc.
What should I do to get the correct data type into table column.

Kind regards
IgorM

  #2  
Old March 21st, 2010, 10:29 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Text value type is calculated on INSERT

Since PhotoMapNo is a text field, you need quotes around the value being
stored:

mobjCommand.CommandText = "INSERT INTO tblMaps " & _
"(PhotoMapNo, ApplicationYear) " & _
"VALUES ('" & msMapNo & "'," & miApplicationYear & ")"

Exagerated for clarity, that last line is

"VALUES ( ' " & msMapNo & " ' ," & miApplicationYear & ")"

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"IgorM" wrote in message
...
Hi

I think this is the right group for my question.
I have a macro in Excel VBA that inserts data into Access accdba database.
The code snippet that inserts the data is:

Public Function InsertPhotoMapNumbers(ByRef miMaxMapNo As Integer, ByRef
miApplicationYear As Integer) As Long
Dim msMapNo As String

'Some code here
msMapNo = CStr(miMapNo) + "/" + CStr(miMaxMapNo)
mobjCommand.CommandText = "INSERT INTO tblMaps(PhotoMapNo,
ApplicationYear)
VALUES (" & msMapNo & "," & miApplicationYear & ")"

'Execute the SQL statement.
mobjCommand.Execute RecordsAffected:=mlRecordsAffected, _
Options:=adCmdText Or adExecuteNoRecords

'Some more code here
End Function


The data in PhotoMapNo column of the tblMaps table should look like:
"255/758", "256/758" etc. The PhotoMapNo column is of text type.
Unfortunately at some point the two values are treated as values and
calculated (divided) so they look like 0,33641, etc.
What should I do to get the correct data type into table column.

Kind regards
IgorM


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:20 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.