Trying to pull last value in Table--and then increment by one--Here is code
Private Sub DateRequest_AfterUpdate()
Dim EDPTRACK As Database
Dim RsTblProject As Recordset
Dim MySql As String
Dim strAA As String
Dim StrDate As String
Dim StrOut As String
Dim Rstsx As Variant
'UserControl Value is input by user
strAA = UserControl.Value
'Date request is input by user--then we take the year add
' "20" to it and get 2001, 2000, 2002, etc
StrDate = Right(DateRequest, 2)
StrDate = "20" + StrDat
'strOut is Straa & StrDate with formatting to match field
'TxtYrVAlue in tblproject---
StrOut = strAA + StrDate
StrOut = strAA & "-" & StrDate
'Get all from tblProject where strout=Txtyrvalue may be 1
' or more in dynaset
'Getting error 3075 invalid syntax in FROM Statement
MySql = " SELECT * FROM TblProject" _
& " WHERE (((TblProject.TxtYrValue))='" + StrOut & "'"
'setting EDPTRACK as Current Database
Set EDPTRACK = CurrentDb
'setting rstblproject as dynaset that meets MYsql Statement
Set RsTblProject = EDPTRACK.OpenRecordset(MySql, _ dbOpenDynaset)
'in dynaset move to last record
RsTblProject.MoveLast
'move value from Last Val to Rstsx increment by one
Rstsx = LastVal + 1
'pad Rstsx to look like 00002
Rstsx = "000" + Rstsx
'take right 3 of string Rstsx
Rstsx = Right(Rstsx, 3)
'Creat ID for Record being input
RequestID.Value = strAA & "-" & StrDate & "-" & Rstsx
'move strout to record being input
TxtYrValue = StrOut
'move Rstsx to record being input to be able to find next record
LastVal = Rstsx
'Do not accept a date more than 30 days prior to current date
If DateRequest < Date - 30 Then
MsgBox ("You must enter a date within the last 30 days!!"
'daterequest not locked if more than 30 days prior to
' current date
DateRequest.Locked = False
'setting focus back to UserControl that has been
'locked and can not be changed for them to go back to
'DateRequest
UserControl.SetFocus
Else
'if date good then lock DateRequest--allow no change
'at input level
DateRequest.Locked = False
End If
End Sub
Any help or ideas would be greatly appreciated--
Private Sub DateRequest_AfterUpdate()
Dim EDPTRACK As Database
Dim RsTblProject As Recordset
Dim MySql As String
Dim strAA As String
Dim StrDate As String
Dim StrOut As String
Dim Rstsx As Variant
'UserControl Value is input by user
strAA = UserControl.Value
'Date request is input by user--then we take the year add
' "20" to it and get 2001, 2000, 2002, etc
StrDate = Right(DateRequest, 2)
StrDate = "20" + StrDat
'strOut is Straa & StrDate with formatting to match field
'TxtYrVAlue in tblproject---
StrOut = strAA + StrDate
StrOut = strAA & "-" & StrDate
'Get all from tblProject where strout=Txtyrvalue may be 1
' or more in dynaset
'Getting error 3075 invalid syntax in FROM Statement
MySql = " SELECT * FROM TblProject" _
& " WHERE (((TblProject.TxtYrValue))='" + StrOut & "'"
'setting EDPTRACK as Current Database
Set EDPTRACK = CurrentDb
'setting rstblproject as dynaset that meets MYsql Statement
Set RsTblProject = EDPTRACK.OpenRecordset(MySql, _ dbOpenDynaset)
'in dynaset move to last record
RsTblProject.MoveLast
'move value from Last Val to Rstsx increment by one
Rstsx = LastVal + 1
'pad Rstsx to look like 00002
Rstsx = "000" + Rstsx
'take right 3 of string Rstsx
Rstsx = Right(Rstsx, 3)
'Creat ID for Record being input
RequestID.Value = strAA & "-" & StrDate & "-" & Rstsx
'move strout to record being input
TxtYrValue = StrOut
'move Rstsx to record being input to be able to find next record
LastVal = Rstsx
'Do not accept a date more than 30 days prior to current date
If DateRequest < Date - 30 Then
MsgBox ("You must enter a date within the last 30 days!!"
'daterequest not locked if more than 30 days prior to
' current date
DateRequest.Locked = False
'setting focus back to UserControl that has been
'locked and can not be changed for them to go back to
'DateRequest
UserControl.SetFocus
Else
'if date good then lock DateRequest--allow no change
'at input level
DateRequest.Locked = False
End If
End Sub
Any help or ideas would be greatly appreciated--