Babycat
Member
- Local time
- Tomorrow, 00:53
- Joined
- Mar 31, 2020
- Messages
- 285
Hi Everyone,
I have tried to search before making this post, but none of result solve my issue (I am a newbie and quite new to Access).
My access file has 2 forms: FrmMain (bound) and FrmID (unbound).
- The Frmmain contents the informtions with primary-key: SoBC (ID), it is default form and display most recent record.
- FrmID is kind of data-entry form which is allow user keys in new ID number.
When user opens access, Frmmain is loaded. On the Form_Load event, I check if database contents any data yet, if no data, a msg reminds user to key in first data. The form FrmID is then openned with an auto suggested "ID name".
When OK_btn on the form FrmID is clicked, it searches in database (tblMain) if this new "ID name" is exist or not, and performs following code:
Code Tags Added by UG
Please help to get out this point since I am already stuck for a day.
I have attached the project file, to see to problem, delete all record and open the form FrmMain.
Best regards, Xuan
I have tried to search before making this post, but none of result solve my issue (I am a newbie and quite new to Access).
My access file has 2 forms: FrmMain (bound) and FrmID (unbound).
- The Frmmain contents the informtions with primary-key: SoBC (ID), it is default form and display most recent record.
- FrmID is kind of data-entry form which is allow user keys in new ID number.
When user opens access, Frmmain is loaded. On the Form_Load event, I check if database contents any data yet, if no data, a msg reminds user to key in first data. The form FrmID is then openned with an auto suggested "ID name".
When OK_btn on the form FrmID is clicked, it searches in database (tblMain) if this new "ID name" is exist or not, and performs following code:
Code Tags Added by UG
Code:
CalculatedStr = Trim(Forms!FrmID!Txt_NewSBC)
ConditionStr = "[SoBC]= '" & CalculatedStr & "'"
SBCvalue = DLookup("SoBC", "tblMain", ConditionStr)
If Not IsNull(SBCvalue) Then
MsgBox "This ID number is already exist!"
Txt_NewSBC.SetFocus
Else
DoCmd.Close acForm, "FrmID"
rs.AddNew
rs!SoBC = CalculatedStr
rs.Update
Application.Echo False 'turn-off screen for a while in order preventing the form flashes to first record
Forms!FrmMain.Requery
DoCmd.GoToRecord acDataForm, "FrmMain", acLast 'the error 2046 orcurs here
Application.Echo True 'turn-on screen
End If
Please help to get out this point since I am already stuck for a day.
I have attached the project file, to see to problem, delete all record and open the form FrmMain.
Best regards, Xuan
Attachments
Last edited by a moderator: