Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

seperating a line of code 1

Status
Not open for further replies.

techkenny1

Technical User
Jan 23, 2009
182
AU
Hi all,
Is it possible to seperate a line of code so that it can be on 2 lines. It would just be easier to work in a smaller space.

Many thanks,

Kp
 

Line1 of code_
Line2 of code

is the same as

Line1 of code Line2 of code

I think the only caveat is that the Underscore (_) cannot occur in the middle of a quote delineated string.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Looking for line continuation character???

Debug.Print chr(95)


Msgbox "HELP" & _
" Code Line continued", vbInforamtion, "Tek-Tips Help!"
 
Hi all,
Many thanks for your replies.
Below i have this code which I neeed to expand.
How can I put this onto 2 or three lines.

myDb.Execute ("INSERT INTO tbl2 ( fld1, fld2,date1,date2,date3,date4,date5,date6,date7 ) SELECT '" & [Forms]![frm1]![fld1] & "', '" & [Forms]![frm1]![fld2] & "', '" & [Forms]![frm1]![date1] & "', '" & [Forms]![frm1]![date2] & "', '" & [Forms]![frm1]![date3] & "', '" & [Forms]![frm1]![date4] & "', '" & [Forms]![frm1]![date5] & "', '" & [Forms]![frm1]![date6] & "', '" & [Forms]![frm1]![date7] & "'")

Many thanks,

KP
 
This is how I would code your statements:
Code:
Dim strSQL as String
strSQL ="INSERT INTO tbl2 ( fld1, fld2, date1, date2, date3, date4, date5, date6, date7 ) " & _
  "SELECT '" & [Forms]![frm1]![fld1] & "', '" & [Forms]![frm1]![fld2] & _
  "', '" & [Forms]![frm1]![date1] & "', '" & [Forms]![frm1]![date2] & _
  "', '" & [Forms]![frm1]![date3] & "', '" & [Forms]![frm1]![date4] & _
  "', '" & [Forms]![frm1]![date5] & "', '" & [Forms]![frm1]![date6] & _
  "', '" & [Forms]![frm1]![date7] & "'"

myDb.Execute strSQL, dbFailOnError
Are the date fields text or dates?


Duane
Hook'D on Access
MS Access MVP
 
Hi dhookom ,
The date fields are date fields.
many thanks for your help. It is greatly appreciated.

KP
 
I would use # to delimit date values rather than '. I just noticed you had "SELECT" without a FROM so you should use "VALUES ()".
Code:
Dim strSQL as String
strSQL ="INSERT INTO tbl2 ( fld1, fld2, date1, date2, date3, date4, date5, date6, date7 ) " & _
  "VALUES ('" & [Forms]![frm1]![fld1] & "', '" & [Forms]![frm1]![fld2] & _
  "', #" & [Forms]![frm1]![date1] & "#, #" & [Forms]![frm1]![date2] & _
  "#, #" & [Forms]![frm1]![date3] & "#, #" & [Forms]![frm1]![date4] & _
  "#, #" & [Forms]![frm1]![date5] & "#, #" & [Forms]![frm1]![date6] & _
  "#, #" & [Forms]![frm1]![date7] & "#)"
myDb.Execute strSQL, dbFailOnError
My other issue with your question is why you have 7 date fields in a table. This raises red flags regarding normalization.

Duane
Hook'D on Access
MS Access MVP
 
Hi all,
I have received the changes to the above code which works reall well, but when a date is copied to tbl 2 is is copied in the US format.How can I change this to the Austrlian format.

Many thanks
KP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top