VB6 & Access 97

Kathleen
05-11-2000, 02:06 PM
Hi,
I am new to this forum, but I am hoping that someone can help me. I have a database in Access 97,that uses VB 6 as a front-end. The database uses DAO in it, and my end dates are not posting to the database at all, they are staying at the default. I have checked all the obvious things and ahve printed out my code to look at it. Is there anything else that I can look for. Help me please...

RCM
05-11-2000, 02:45 PM
What do you mean by your dates are not posting to the database? Also I'm not sure what default is. Could you give an example of the input you are attempting and the way you are trying to save to the database.

Ron

Kathleen
05-11-2000, 02:48 PM
Here is the code that is in VB 6. I inherited this database from someone else. It is in DAO and will be switched over to ADO soon enough but for right now I just need to keep it working. this hasn't worked in a few years.

Private Sub tbEndDate_GotFocus(Index As Integer)
If tbEndDate(Index) = "1/1/80" Then
tbEndDate(Index) = ""
tbEndDate(Index).ForeColor = vbWindowText
End If
SelectText ActiveControl
End Sub

Private Sub tbEndDate_LostFocus(Index As Integer)
If tbEndDate(Index) = "" Then
tbEndDate(Index).ForeColor = vbWindowBackground
tbEndDate(Index) = "1/1/80"
End If
If tbEndDate(Index) <> "1/1/80" Then
tbEndDate(Index).ForeColor = vbWindowText
Set c = tbEndDate(Index)
dt = c.Text
f = InStr(dt, "/")
If f > 0 Then Exit Sub
If Len(dt) = 6 Then
c.Text = Left(dt, 2) & "/" & Mid(dt, 3, 2) & "/" & Right(dt, 2)
ElseIf Len(dt) = 5 Then
c.Text = Left(dt, 1) & "/" & Mid(dt, 2, 2) & "/" & Right(dt, 2)
ElseIf Len(dt) = 4 Then
c.Text = Left(dt, 1) & "/" & Mid(dt, 2, 1) & "/" & Right(dt, 2)
Else
MsgBox "Please enter dates as mmddyy.", vbOKOnly, "TNT Contract Summary"


End If
dtaRoomTerms.Recordset.Update
End If
End Sub

klabranche
05-11-2000, 05:02 PM
kathleen,

It's hard to see what is going on with your code snippet but...

First is how the date is entered. Looking at the code, the date would be displayed in the format of mm/dd/yy but it appears that you would like it entered as mmddyy. This could be confusing to the user and if they type in a date formatted as mm/dd/yy and not mmddyy the subroutine exits without any processing.

I have had problems with Access not liking dates because of the way it was formatted. Check the Access field and be sure that you are giving a format that the field is expecting.

You may want to look at rewriting the code for formatting the date...
It seems to me it could create incorrect dates based on input
For example if the date = 12/1/00 or 12100 (typed into the control)
the code would spit out a date of 1/21/00

I would suggest dropping the date formatting code and let the user enter the date as mm/dd/yy and use the IsDate function to test for date validity.

You may also look into renaming the variables and
indenting your code to make it a little easier to
maintain. As well as putting an error routine if
it's not already there to see if an error is generated
that would possibly give further clues as to why the
database isn't updating.

I'm assuming c is a TextBox object and dt is a string and
not a date variable. If dt is a date variable then you would always get the msgbox popping up from the else statement. If c is not a TextBox object the could should bomb.

I'm also assuming dtaRoomTerms is your data control and it is tied correctly to your form and the tbEndDate control is correctly bound to it.

With the above code I can't see much. With a data control when you move off of the record that would also try to save the record so putting the update statement in the lost focus event may not be necessary if the form is moving between records but that's a mute point really. You can attach your program to a message but I don't know if that will help without knowing the database side of it as well.

Let me know if this helps
Good Luck,
Kevin

RCM
05-11-2000, 06:09 PM
Another option is to look into the masked Edit Control. You can specify the mask you wish i.e. dd/mm/yy. I would consider a complete overhaul if not a total rewrite for this project. If the rest of the code is as difficult to read as the snipets here you may actualy save time and improve on the overall application.

Good Luck,

Ron

klabranche
05-11-2000, 06:27 PM
I agree with Ron, but I was chicken to say anything...

Kathleen
05-12-2000, 09:34 AM
I got the database to work. After much banging my head against the cube wall and reading the code. I put in that mask and the user(problem user) was able to understand what is required of her now. Thanks all of you who replied. I am sure I will be coming here more.

blade2009
10-24-2002, 02:16 AM
i have the same problem as kath
i am using access 97 and dao and vb front end

i trying to get the user to type in the date in dd/mm/yyyy format cause where i live we follow this format. When that is done i want to get that date and subtract that from the system date. If the answer is greater than or equal to 60 i want it to advise the user that the record is overdue.

i tried going to the componenet and references in vb but it said that i couldnt do it cause it was conflicting with my module,form or variable.

this sucks



i hope someone could help me cause this is killing me

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum