|
-
Feb 2nd, 2000, 10:00 PM
#1
Thread Starter
Member
I have been writing a program for a while now, its worked its way up to an inspiring but not really impressive 7 frames.
i have one database showing data from one recordset, and i now want to save from a different one but my code will just not work.
i built it up from examples and help files so i dont have a terrific grasp on the ideas behind.
someone pls tell me what is wrong with this code??
--------------------------------------------
Private Sub cmdSave_Click()
'Check to see if this client already exists in the database
' if so Abort Add
' if not Add this record to database.
With Data4.Recordset
ClientID = FormID(txtFName, txtLName, txtType)
Criterion = "ClientID = " & Chr$(34) & ClientID & Chr$(34)
.FindFirst Criterion
If Not .NoMatch Then
MsgBox "This client is already recorded 10 times within the database" & vbCrLf & _
"You cannot include them again", vbCritical, "ATTEMPT TO REPLICATE RECORD"
Exit Sub
Else
'Add this record to the database
.AddNew
EnterRecordData
.Update
.Requery
End If
End With
End Sub
Function EnterRecordData()
With Data4.Recordset
!First_Name = txtFName
!Last_Name = txtLName
!Department = txtDept
!Address = txtAddress
!Vehicle_Type = txtType
!Cyear = year
!inservicedate = DTDate(0)
!ClientID = ClientID
End With
End Function
Function FormID(FName, LName, Vehicle)
Dim i As Integer
Dim Criterion
While Len(LName) < 4
LName = LName & "_"
Wend
ClientID = Left$(LName, 4) & Left$(FName, 2) & Left$(Vehicle, 2)
For i = 0 To 9
Criterion = "ClientID = " & ClientID & CStr(i)
While Data4.Recordset.NoMatch
Data4.Recordset.FindFirst Criterion
Data4.Recordset.MoveNext
Wend
Next i
ClientID = ClientID & CStr(i - 1)
End Function
-
Feb 3rd, 2000, 12:44 PM
#2
Frenzied Member
It would help a great deal if you told us which line it stopped on when the error happens.
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
-
Feb 3rd, 2000, 02:47 PM
#3
Thread Starter
Member
Ooops sorry buzby
i forgot that cos it meant nuthin to me, it stopped on the line
.update
the message was something about FName cant be a zero length, but i typed in data to each field before running it
Cheers for any help
-
Feb 3rd, 2000, 06:14 PM
#4
Frenzied Member
The error "[field] cannot be zero length" means just that - you are trying to store an empty string to the database in a field that can't be empty. When the program stops at the .Update, don't stop the program running, go to the debug window (CTRL+G) and type
? txtFNAme
to see what is in the txtFName field - I bet it'll be nothing! This probably means that the textbox on the screen is not called txtFName, check the spelling etc.
Note: If you used txtFName.Text each time it would guarantee that the database gets stored with the value in the .Text property - I've noticed weird things happening when you don't put the property name in (though not on a textbox, granted)
Let me know how you get on.
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|