Need Help with this code!! Please Help!!

  • Thread starter Thread starter samueltjones
  • Start date Start date
S

samueltjones

Guest
Here is the code and it's purpose is to transfer a spreadsheet range into the database. It works fine apart from I need the name to always be the same. The Date - 4 works fine on it's own, but I also need it to add some text on to the end which in this case is Yr 3. Here is the code please have a go and write back. Thanks!! :)

P.s. I have coloured red the problem area.

'------------------------------------------------------------
' transferspreadsheetyr3
'
'------------------------------------------------------------
Function transferspreadsheet_test()
On Error GoTo transferspreadsheet_test_Err
DoCmd.transferspreadsheet acImport, 8, Date - 4 + "Yr 3", "C:\Documents and Settings\All Users\Documents\My Work\I.T\Chosen Project\Register Yr 3.xls", True, "import"
MsgBox "Transfer of the Yr 3's week attendance successful!!"


transferspreadsheet_test_Exit:
Exit Function

transferspreadsheet_test_Err:
MsgBox Error$
Resume transferspreadsheet_test_Exit

End Function
 
shouldn't the "+" be a "&"

I'm still learning but that looks suspect
 
texasalynn said:
shouldn't the "+" be a "&"

I'm still learning but that looks suspect

Correct, if you are wanting to concatinate (or however you spell it) items you use the & sign.

Secondly, if you are wanting space between the "Yr 3" and the verbiage before it, you need to include it by either " Yr 3" or & " " & "Yr3". I personally use the 2nd one. I guess it can be preference.

I am sure someone will correct me if I am wrong. :o
 
selenau837 said:
Correct, if you are wanting to concatinate (or however you spell it) items you use the & sign.

...actually right and wrong. You can use either the '+' or the '&' to concatenate:D a string, however the problem arises when attempting to use the '+' with both an integer and a string. Because the integer is first in the evaluation of the statement, it assumes that the + is for math, not concatenation, and therefor you blow a type mismatch.

I would personally use:
Code:
(Date - 4) & "Yr3"
selenau837 said:
I am sure someone will correct me if I am wrong. :o
Would you expect anything less?;)
 
Last edited:
Bodisathva said:
...actually right and wrong. You can use either the '+' or the '&' to concatenate:D a string, however the problem arises when attempting to use the '+' with both an integer and a string. Because the integer is first in the evaluation of the statement, it assumes that the + is for math, not concatenation, and therefor you blow a type mismatch.

See you learn something new everyday. I at least had part of it correct. :o


Would you expect anything less?;)

*whispers* Thanks for taking it easy, I might have cried. :p
 
another point,

Anything + Null = Null
Anything & Null = Anything

Peter
 
Thanks a Lot!!

Thanks a lot all of you for your great help. I know where to come next time I have any problems. Thanks again for your help. :)
 

Users who are viewing this thread

Back
Top Bottom