Textbox Values Validate and Store (1 Viewer)

waseem0888

Member
Local time
Today, 18:27
Joined
Jul 25, 2020
Messages
51
I am trying to store values from textbox to tables first validate the empty textbox and then store the text through button but the button is not responding kindly check my code where I am wrong.

Private Sub btnSave_Click()
On Error GoTo Error
Validation
If valValue <> 1 Then
Exit Sub

Else
If MsgBox("Do you want to Save the records", vbYesNo + vbExclamation, "Confirmation!") = vbYes Then
CurrentDb.Execute "INSERT INTO [tblNCR] (Project,Type,Received,Closed,CloseAgree,Repeated,UnderReview,CurrentMonth,CurrentYear) VALUES ('" & Me.cmbProject & "','" & Me.txtNCR & "','" & Me.NcrRecv & "','" & Me.NcrCls & "','" & Me.Ncragre & "','" & Me.NcrRep & "','" & Me.NcrUndrRvw & "','" & Me.CmbMonth & "','" & Me.cmbYear & "')"
CurrentDb.Execute "INSERT INTO [tblSOR] (Project,Type,Received,Closed,CloseAgree,Repeated,UnderReview,CurrentMonth,CurrentYear) VALUES ('" & Me.cmbProject & "','" & Me.txtSOR & "','" & Me.SorRecv & "','" & Me.SorCls & "','" & Me.SorAgre & "','" & Me.SorRep & "','" & Me.SorUnderRevw & "','" & Me.CmbMonth & "','" & Me.cmbYear & "')"
CurrentDb.Execute "INSERT INTO [tblITP] (Project,Type,Submitted,Approved1stTime,StatusA,StatusB,StatusC,StatusD,UnderReview,CurrentMonth,CurrentYear) VALUES ('" & Me.cmbProject & "','" & Me.txtITP & "','" & Me.txtItpSub & "','" & Me.txtItpApp1 & "','" & Me.txtITPStsA & "','" & Me.txtITPStsB & "','" & Me.txtITPStsC & "','" & Me.txtITPStsD & "','" & Me.txtITPUR & "','" & Me.CmbMonth & "','" & Me.cmbYear & "')"
CurrentDb.Execute "INSERT INTO [tblWIR] (Project,Type,Submitted,Approved1stTime,StatusA,StatusB,StatusC,StatusD,UnderReview,CurrentMonth,CurrentYear) VALUES ('" & Me.cmbProject & "','" & Me.txtWIR & "','" & Me.txtWirSub & "','" & Me.txtWirApp1 & "','" & Me.txtWirStsA & "','" & Me.txtWirStsB & "','" & Me.txtITPStsC & "','" & Me.txtWirStsD & "','" & Me.txtWirUR & "','" & Me.CmbMonth & "','" & Me.cmbYear & "')"
CurrentDb.Execute "INSERT INTO[tblMeeting](Project,QualityTraining,SiteInspections,DocumentControl,MeetingClient,MeetingInternal,MeetingHQ,CurrentMonth,CurrentYear)VALUES ('" & Me.cmbProject & "','" & Me.txtQltyTrng & "','" & Me.txtSiteInspc & "','" & Me.txtDC & "','" & Me.txtMeetingClient & "','" & Me.txtMeetingInternal & "','" & Me.txtMeetingHQ & "','" & Me.CmbMonth & "','" & Me.cmbYear & "')"
MsgBox "Values are stored successfully....."
End If
End If
Error: If Err.Number > 0 Then MsgBox Err.Number & Err.Description
End Sub

Public Sub Validation()
On Error Resume Next
valValue = 0
If IsNull(Me.cmbProject) Or Me.cmbProject = "" Then
MsgBox "Please Select Project ...!", vbCritical, msgReq
Me.cmbProject.SetFocus
Exit Sub
ElseIf IsNull(Me.CmbMonth) Or Me.CmbMonth = "" Then
MsgBox "Please Select Month ...!", vbCritical, msgReq
Me.CmbMonth.SetFocus
Exit Sub
ElseIf IsNull(Me.cmbYear) Or Me.cmbYear = "" Then
MsgBox "Please Select Year ...!", vbCritical, msgReq
Me.cmbYear.SetFocus
Exit Sub
ElseIf IsNull(Me.NcrRecv) Or Me.NcrRecv = "" Then
MsgBox "Please Insert NCR Receive Value...!", vbCritical, msgReq
Me.NcrRecv.SetFocus
Exit Sub
ElseIf IsNull(Me.NcrCls) Or Me.NcrCls = "" Then
MsgBox "Please Insert NCR Close Value...!", vbCritical, msgReq
Me.NcrCls.SetFocus
Exit Sub
ElseIf IsNull(Me.Ncragre) Or Me.Ncragre = "" Then
MsgBox "Please Insert NCR Agree within time frame Value ...!", vbCritical, msgReq
Me.Ncragre.SetFocus
Exit Sub
ElseIf IsNull(Me.NcrRep) Or Me.NcrRep = "" Then
MsgBox "Please Insert NCR Repeated Value...!", vbCritical, msgReq
Me.NcrRep.SetFocus
Exit Sub
ElseIf IsNull(Me.NcrUndrRvw) Or Me.NcrUndrRvw = "" Then
MsgBox "Please Insert NCR Under Review Value...!", vbCritical, msgReq
Me.NcrUndrRvw.SetFocus
Exit Sub
ElseIf IsNull(Me.SorRecv) Or Me.SorRecv = "" Then
MsgBox "Please Insert SOR Receive Value...!", vbCritical, msgReq
Me.SorRecv.SetFocus
Exit Sub
ElseIf IsNull(Me.SorCls) Or Me.SorCls = "" Then
MsgBox "Please Insert SOR Close Value...!", vbCritical, msgReq
Me.SorCls.SetFocus
Exit Sub
ElseIf IsNull(Me.SorAgre) Or Me.SorAgre = "" Then
MsgBox "Please Insert SOR Agree within time frame Value ...!", vbCritical, msgReq
Me.SorAgre.SetFocus
Exit Sub
ElseIf IsNull(Me.SorRep) Or Me.SorAgre = "" Then
MsgBox "Please Insert SOR Repeated Value...!", vbCritical, msgReq
Me.SorAgre.SetFocus
Exit Sub
ElseIf IsNull(Me.SorUnderRevw) Or Me.SorUnderRevw = "" Then
MsgBox "Please Insert SOR Under Review Value...!", vbCritical, msgReq
Me.SorUnderRevw.SetFocus
Exit Sub
ElseIf IsNull(Me.txtWirSub) Or Me.txtWirSub = "" Then
MsgBox "Please Insert WIR submitted Value...!", vbCritical, msgReq
Me.txtWirSub.SetFocus
Exit Sub
ElseIf IsNull(Me.txtWirApp1) Or Me.txtWirApp1 = "" Then
MsgBox "Please Insert WIR Approved 1st Time Value...!", vbCritical, msgReq
Me.txtWirApp1.SetFocus
Exit Sub
ElseIf IsNull(Me.txtWirStsA) Or Me.txtWirStsA = "" Then
MsgBox "Please Insert WIR status A Value...!", vbCritical, msgReq
Me.txtWirStsA.SetFocus
Exit Sub
ElseIf IsNull(Me.txtWirStsB) Or Me.txtWirStsB = "" Then
MsgBox "Please Insert WIR status B Value...!", vbCritical, msgReq
Me.txtWirStsB.SetFocus
Exit Sub
ElseIf IsNull(Me.txtWirStsC) Or Me.txtWirStsC = "" Then
MsgBox "Please Insert WIR status C Value ...!", vbCritical, msgReq
Me.txtWirStsC.SetFocus
Exit Sub
ElseIf IsNull(Me.txtWirStsD) Or Me.txtWirStsD = "" Then
MsgBox "Please Insert WIR status D Value...!", vbCritical, msgReq
Me.txtWirStsD.SetFocus
Exit Sub
ElseIf IsNull(Me.txtWirUR) Or Me.txtWirUR = "" Then
MsgBox "Please Insert WIR Under Review Value...!", vbCritical, msgReq
Me.txtWirUR.SetFocus
Exit Sub
ElseIf IsNull(Me.txtItpSub) Or Me.txtItpSub = "" Then
MsgBox "Please Insert ITP submitted Value...!", vbCritical, msgReq
Me.txtItpSub.SetFocus
Exit Sub
ElseIf IsNull(Me.txtItpApp1) Or Me.txtItpApp1 = "" Then
MsgBox "Please Insert ITP Approved 1st Time Value...!", vbCritical, msgReq
Me.txtItpApp1.SetFocus
Exit Sub
ElseIf IsNull(Me.txtITPStsA) Or Me.txtITPStsA = "" Then
MsgBox "Please Insert ITP status A Value...!", vbCritical, msgReq
Me.txtITPStsA.SetFocus
Exit Sub
ElseIf IsNull(Me.txtITPStsB) Or Me.txtITPStsB = "" Then
MsgBox "Please Insert ITP status B Value...!", vbCritical, msgReq
Me.txtITPStsB.SetFocus
Exit Sub
ElseIf IsNull(Me.txtITPStsC) Or Me.txtITPStsC = "" Then
MsgBox "Please Insert ITP status C Value ...!", vbCritical, msgReq
Me.txtITPStsC.SetFocus
Exit Sub
ElseIf IsNull(Me.txtITPStsD) Or Me.txtITPStsD = "" Then
MsgBox "Please Insert ITP status D Value...!", vbCritical, msgReq
Me.txtITPStsD.SetFocus
Exit Sub
ElseIf IsNull(Me.txtITPUR) Or Me.txtITPUR = "" Then
MsgBox "Please Insert ITP Under Review Value...!", vbCritical, msgReq
Me.txtITPUR.SetFocus
Exit Sub
Else
valValue = 1
End If
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:27
Joined
May 7, 2009
Messages
19,242
is this public variable?

you must Declare it inside the Form:

Option Compare Database
Option Explicit

Dim valValue As Integer
 

waseem0888

Member
Local time
Today, 18:27
Joined
Jul 25, 2020
Messages
51
is this public variable?

you must Declare it inside the Form:

Option Compare Database
Option Explicit

Dim valValue As Integer
Yes sir it's a public variable. Thank you so much yes i declared but it was deleted by mistake and didn't notice. Thank you for your help :)
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:27
Joined
Feb 19, 2002
Messages
43,271
Is there some reason you are not using a bound form? Access is a RAD (Rapid Application Development) tool and not using bound forms eliminates its best feature. Why use Access at all if you are going to eschew its best feature?

When you use a bound form, the validation belongs in the form's BeforeUpdate event where you can cancel the update if you find an error. That gives you complete control over whether or not a record gets saved.

Also, when you post code, please use the forum tools and make sure it is properly indented. What you posted is very difficult to read.
 

Users who are viewing this thread

Top Bottom