I've got a form "AllowEntryForm" and upon loading, I want to do this:
I've got a table called "IDTable" and in that table is a field called "ID" where a string will be stored. I want to get that string in the IDTable and compare it to another string (PassCode). If they match then the form (AllowEntryForm) closes and opens up a different form (MainForm). If they do not match then the form (AllowEntryForm) opens up where they will have to enter the string that will be stored in the table.
I'm not sure how to do this but I attempted to figure it out. Currently I have "AllowEntryForm" as the form that opens at startup.
I would like to do this whole process when the database is opened but I don't know how to tell Access to do that at startup so I just tried doing it upon the loading of the form that opens at startup.
This is how I am attempting to do it:
Private Sub Form_Load()
Dim IDNum As String
Dim stMainForm As String
Dim stAllowEntryForm As String
Dim stIDTable As String
Dim PassCode As String
PassCode = "ABC123"
stMainForm = "MainForm"
stAllowEntryForm = "AllowEntryForm"
stIDTable = "IDTable"
IDNum = "SELECT [" & ID & "] From [" & stIDTable & " ]"
If IDNum <> PassCode Then
DoCmd.OpenForm stAllowEntryForm
ElseIf IDNum = PassCode Then
DoCmd.Close stAllowEntryForm
DoCmd.OpenForm stMainFormName
End If
End Sub
I am not getting any errors but my problem is even though the string in the table matches the PassCode, it is opening up the AllowEntryForm but it is supposed close it and open up a different form.
Does anyone have any suggestions?
I've got a table called "IDTable" and in that table is a field called "ID" where a string will be stored. I want to get that string in the IDTable and compare it to another string (PassCode). If they match then the form (AllowEntryForm) closes and opens up a different form (MainForm). If they do not match then the form (AllowEntryForm) opens up where they will have to enter the string that will be stored in the table.
I'm not sure how to do this but I attempted to figure it out. Currently I have "AllowEntryForm" as the form that opens at startup.
I would like to do this whole process when the database is opened but I don't know how to tell Access to do that at startup so I just tried doing it upon the loading of the form that opens at startup.
This is how I am attempting to do it:
Private Sub Form_Load()
Dim IDNum As String
Dim stMainForm As String
Dim stAllowEntryForm As String
Dim stIDTable As String
Dim PassCode As String
PassCode = "ABC123"
stMainForm = "MainForm"
stAllowEntryForm = "AllowEntryForm"
stIDTable = "IDTable"
IDNum = "SELECT [" & ID & "] From [" & stIDTable & " ]"
If IDNum <> PassCode Then
DoCmd.OpenForm stAllowEntryForm
ElseIf IDNum = PassCode Then
DoCmd.Close stAllowEntryForm
DoCmd.OpenForm stMainFormName
End If
End Sub
I am not getting any errors but my problem is even though the string in the table matches the PassCode, it is opening up the AllowEntryForm but it is supposed close it and open up a different form.
Does anyone have any suggestions?