Memo Username and Date stamp - datetime

I am new to Access and programing codes. I am building a data base where daily notes for issues can be kept. I want the end user to be able to view past records and make updates. However I do not want the to alter text previously put in the memo field containing the issue they are wanting to update. Also I am wanting to flag there new input with username and date/time.
I am try to accomplish this by inserting the following code into the AfterUpdate()
Private Sub Text0_AfterUpdate()
Me.Text0 = Me.Text0.Value & " " & UserName() & " # " & Now()
End Sub
I used Text0 because I am testing this code. Anyway this works in an unbound text box perfectly for flagging the new input. However when I try using this in my form with bound textboxes it fails to work. Any ideas? If I get this working I want to find a way to prevent editing on previously entered text but that is not a must.

The form containing the memo textbox for update was corrupt. By copying and pasting to create a new form with everything but the textbox I was having problems with I fixed my problem. I just made a new text box in the new form.

Related

Textbox on ticket reply not displaying multiple lines

My ticketing system has a textbox for users to enter text and create/reply to a ticket. Currently when they enter multiple lines of text, once submitted, it will display as one line instead of two lines. We are storing all of the data in sql database and when displaying the responses they are showing as one line.
How can I get the value submitted to store in the database with multiline and then display back on the page with multiline when it pulls it from the database.
Thanks!
When reading the string from the database in the code behind, I had to use String.Replace(Environment.NewLine, "<br>")

VB.Net Looping over text boxes to check if they contain only numbers

Im working on a simple university project, which has to registers a new member. Right now im busy with form validation.
Some of my textboxes can only contain text and not letters, the code I use to check if the textboxes which must only accept text is as follows:
'check textboxes contains only characters'
'initial'
If Not System.Text.RegularExpressions.Regex.Match(vinital, "^[a-z]*$", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Success Then
MsgBox("Initial can only contain text .")
End If
My question
Instead of doing one if statment at a time for every textbox, how can I loop over them using similar code as above to validate for text only.
You could try to put all your controls in a Panel and then iterate through it like this (untested, but you get the idea):
Dim ctrl As Control
For Each ctrl In Panel1.Controls 'Me.Controls should also work, I think.
If (ctrl.GetType() Is GetType(TextBox)) Then
Dim txt As TextBox = CType(ctrl, TextBox)
'check content of txt here
End If
Next

Date and Time picker in ASP.net

I know this question is on SO a few times already but I cannot find a working or suitable answer.
I want a date picker which includes a time picker. I don't want any fancy frills etc, just something that works. Preferably one control I can drag into the tool box in VS, register at the top and work with. I have been playing around with many versions the last few days and I can't get one to work. They normally seem to include too many files for me or something stupid. A project I am working on now hinges on this stupid thing so any advice would be welcome. I have previously managed to get a calendar control and put some validation on a text-box to pick times. However I cannot take both of these values and enter them into my database as on Date-time field because when I try to use "Selected-date" to get the time it naturally says that text-boxes cannot be members of the "Selected-date" property.
As I have a calendar control in to pick the date and a validated textbox to type in the time I tried to use the following code.
Protected Sub Button1_Click(sender As Object, e As EventArgs)
Dim time As String() = txtTime.SelectedDate.ToString().Trim().Split(" "C)
Dim [date] As String() = cldDate.SelectedDate.ToString().Trim().Split(" "C)
Dim datetime__1 As String = [date](0) & " " & time(1) & time(2)
Dim DateTimeValue As DateTime = DateTime.Parse(datetime__1)
Response.Write(DateTimeValue.ToString())
' Update database with DateTimeValue.
End Sub
The code txtTime.SelectedDate.ToString() is a problem here. It says that SelectedDate is not a supported member of textbox. This is code that I have came across. I'm pretty new to coding.
You could create a new instance of the DateTime structure. The DateTimePicker.SelectedValue returns a Nullable(Of DateTime), so you can use the values of this to create a new DateTime (along with the values from your textboxes).
For example:
Dim myDateTime As New DateTime(cldDate.SelectedDate.Year, cldDate.SelectedDate.Month, cldDate.SelectedDate.Day, HourValue, MinuteValue, 0)
Just replace HourValue and MinuteValue with your values from your textboxes. Note you should convert these to Integers.
Note the 0 at the end represents seconds.
This should save to the database fine.
For more info on DateTime see here.
if jQuery is an option i would look at this plug in
clean and easy to implement
You don't mention whether a commercial product would be an option for you.
We are using telerik's RadDateTimePicker in our projects (and there are certainly other commercial products). See this page for a demo of the datetime picker control.

how do I reference the values from textboxes on form submit that reside in my usercontrol? ASP.NET(VB)

I can't believe I couldn't find an answer to this question after literally hours of searching the web. Is this so basic that everyone just knows how to do this? As you might have guessed I'm new to asp.net(vb).
My situation:
I have a large form that reuses several elements, so I decided to create a usercontrol with some common fields. The problem is when the form is filled out by a user and submitted, how do I reference those values so I can input them to my database???
Example:
Using Conn As New SqlConnection(connect)
Using Cmd As New SqlCommand(SQL, Conn)
Cmd.Parameters.AddWithValue("#Acct_Company", txtPartner.Text)
Cmd.Parameters.AddWithValue("#Acct_AccountNum", txtPartnerAccount.Text)
So, above two Cmd lines are for normally inserted textboxes in my form, but what would the line look like to reference any usercontrol form fields?
Any help would be greatly appreciated.
You need to expose the controls some how to the page that contains the user control. One way to to this is like this (within the control code):
Property CompanyName As String
Get
Return txtPartner.Text
End Get
Set(value As String)
txtPartner.Text = value
End Set
End Property
Then, the page containing the user control can access the value like this:
myControl.CompanyName

vb.net to reduce code for displaying data in textboxes

On the page I have created I have a search facility that if a doctors number is searched it will bring up the doctors details, once search button is clicked the results are displayed in textboxes (I cannot use gridviews because this is not wanted)
sample of code placed on the search button
Query statement = "SELECT DocNumber FROM tblDoctor WHERE DNum LIKE '%"
execute the query and get the result
The result is converted to string and Execute Scalar is used
DocNum.Text = Result1
Query statement = "SELECT DocName FROM tblDoctor WHERE DNum LIKE '%"
execute the query and get the result
The result is converted to string and Execute Scalar is used
DocName.Text = Result2
etc.... there are are 14 other textboxes that I want too display data in, so there is a large amount of repeated lines of code following the structure above. Can anyone suggest a better way of doing this?
Another problem of repetition of code comes from the prev page that is linked to it. The page before has a summary of details of doctors, once the row is clicked it takes you to this page displaying a more detailed view of their personal details. The doctor number selected will be passed onto the more detailed view using a querystring so I have the code
Automatic population of the selected doctors will fill the labels
on page load
Request the query string and store into variable dNum
Query statement = "SELECT DocNumber FROM tblDoctor WHERE DNum = " & dNum"
Get result from query convert to string and use execute scalar
lblDocNum.Text = Res1
Query statement = "SELECT DocNumber FROM tblDoctor WHERE DNum = " & dNum"
Get result from query convert to string and use execute scalar
lblDocNum.Text = Res1
etc...
What I am doing works correctly but the coding style looks poor. Any help would be much appreciated.
Thank you
Why not use a DataReader or DataSet or whatever you prefer to return the whole record, then simple move from column to column and populate the textboxes that way? Instead of returning one value at a time.
If the goal is less code,
SELECT * FROM tblDoctor WHERE xxx
into a DataTable or DataReader, as Thyamine suggested, above.
From there, you could also put the textboxes in an HTML table in a Repeater which you will bind to that datatable. You won't have to individually assign any of the values, the databinding will do it for you!
I know that people think HTML tables are evil but it's the easiest way to line up the labels I assume you will also want.
I also know that the control I suggested is called a Repeater but you only have one record. If you don't tell the compiler, I won't. :)
From parts of your question, it sounds like you're wondering whether to send all of the bits of information along in the querystring but that doesn't sound like a good idea to me because it invites users to mess with the data in the querystring.
You didn't mention - are these textboxes meant for editing? A Save button inside the Repeater would have easy access to all of the controls to build your update statement. You could also put the Save button outside the repeater and refer to the repeater's first Item to find the controls.

Resources