VB icon

CRecordEdit v. 2.0

Email
Submitted on: 1/5/2015 4:25:00 PM
By: Neil McGuigan (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages), HTML
Views: 807
 
     creates an HTML form given an ADO recordset. Uses different controls (textbox, checkbox, textarea) for different datatypes. Determines maxlength property based on datatype. Keeps some useful info in hidden fields.

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :CRecordEdit v. 2.0
'**************************************
Copyright (C) 2001, Neil McGuigan. All rights reserved. This software is licenced.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: CRecordEdit v. 2.0
' Description:creates an HTML form given an ADO recordset. Uses different controls (textbox, checkbox, textarea) for different datatypes. Determines maxlength property based on datatype. Keeps some useful info in hidden fields.
' By: Neil McGuigan (from psc cd)
'
' Inputs:Add your own HTML and JavaScript to sections of the form:
.moreTblTags
.moreCaptionTags
.moreCellTags
.moreRowTags
Other:
.uniqueField - defaults to 0. change if needed.
.print(rs) - prints one record from the recordset.
'
' Returns:uses response.write to output nicely formatted HTML (with tabs and linefeeds).
'
' Assumes:Tested on all JET/ADO datatypes. Extensive SQL server testing coming soon. Should work though.
There are some hidden fields with no value that you can update with JS if you like (example 'selected field').
You should use cascading style sheets to format the form.
NS & IE event management in next version.
'
' Side Effects:Writes query string to a hidden field if you don't use a view.
Does not correctly determine maxlength for numeric types (except short int, and byte).
'**************************************

<%
'TO DO:
' cross-browser event handling (caption onclick, field on change)
'shouldn't use HTML tags for formatting, use CSS
'verify with all SQL Server types.
'add 'goto hyperlink' and 'sendmail' icons if field contains (only) a url
'fix maxlength. shows number of bits for numbers.
' end to do
class CRecordEdit
	public moreTblTags
	public moreRowTags
	public moreCaptionTags
	public moreCellTags
	
	private m_iPKFld
	
	public property let uniqueField(byval p)
		m_iPKFld=uniqueField
	end property
	
	private sub class_initialize()
		m_iPKFld=0
	end sub
	public sub print(byref rs)
		with response
			.write "<table"
			.write " " & moreTblTags
			.write ">" & vbCR
			dim fld
			for each fld in rs.fields
				.write vbTab & "<tr"
				.write " " & moreRowTags
				.write ">"
				.write "<th"
				select case fld.type
					case 3,17,2,131,5,6,4,130,129,202,200,72,7,135,203,201
						.write " onClick=""" & fld.name & ".focus();"""
					case 11 : .write " onClick=""" & fld.name & ".checked=!" & fld.name & ".checked;""" 'boolean
				end select
				.write " " & moreCaptionTags
				.write ">"
				.write fld.name
				.write "</th>"
				.write "<td"
'				.write " " & moreCellTags
				.write ">"
				call showControl(fld)				
				.write "</td>"
				.write "</tr>" & vbCR
			next
			.write "</table>"
			.write vbCR & "<input type=""hidden"" name=""query"" value=""" & rs.source & """>"
			.write vbCR & "<input type=""hidden"" name=""dateAccessed"" value=""" & now() & """>"
			.write vbCR & "<input type=""hidden"" name=""uniqueField"" value=""" & rs.fields(m_iPKFld).name & """>"
			.write vbCR & "<input type=""hidden"" name=""changedFields"" value="""">"
			.write vbCR & "<input type=""hidden"" name=""selectedField"" value="""">"
			.write vbCR & "<input type=""hidden"" name=""selectedValue"" value="""">"			
		end with
	end sub
	private sub showControl(byref fld)
		dim name,val,maxLength,width,ftype
		name=fld.name
		val=fld.value
		maxLength=fld.definedSize
		width=""
		ftype=fld.type
		
		'took out widths, use CSS
		select case ftype
			case 7,135 'dates
				maxLength=22
'				width=21
			case 3,4,5,6
				maxLength=99 'should figure this out actually
			case 2 'adSmallInt (-32,000)
				maxLength=7
'				width=7
			case 72 'GUID
				maxLength=38
'				width=43
			case 17 'byte
				maxlength=3
'				width=3
		end select
		
		select case ftype
			case 3,17,2,131,5,6,4,130,129,202,200,72,7,135 'regular text
				with response
					.write "<input"
					.write " type=""text"""
					.write " name=""" & name & """"
					.write " value=""" & val & """"
					if len(maxLength)>0 then .write " maxlength=""" & maxLength & """"
'					if len(width)>0 then .write " size=""" & width & """"
					.write " onFocus=""this.select();"""
					.write " " & moreCellTags
					.write ">"
				end with
			case 203,201 'memo
				with response
					.write "<textarea"
					.write " name=""" & name & """"
					.write " rows=""4"""
					.write " cols=""40"""
					.write " onFocus=""this.select();"""										
					.write " " & moreCellTags
					.write ">"
					.write val
					.write "</textArea>"
				end with
			case 11 'boolean
				with response
					.write "<input"
					.write " type=""checkBox"""
					.write " name=""" & name & """"
					.write " value=""true"""
					if val then .write " checked "
					.write moreCellTags
					.write ">"
				end with
			case else
				response.write "<binary>"
		end select
				with response
					.write vbCR & vbTab & "<input type=""hidden"" name=""" & name & "UNDERLYING"" value=""" & val & """>"
					.write vbCR & vbTab & "<input type=""hidden"" name=""" & name & "ADOTYPE"" value=""" & ftype & """>"
				end with
	end sub
end class
%>


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.