If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Jeez, how to make a form hidden and to store value?
I was cracking my head on this one yesterday, I need some examples of how
to make a hidden form and to store a value there and refer to it from a field in another form. I managed to use AutoExe macro to open form and then run "WindowHide" command, it works, but the data is lost or nowhere to be stored. Thanks for any advice -- Message posted via http://www.accessmonster.com |
#2
|
|||
|
|||
Alex,
Hiding a form just to provide access to a value is not the way to do it. Declare a Public variable in a standard module. Create a Public function in the same module to return the value of that variable. Then just use the function from your form control. 'In the module Public myVariable As Integer Public Function GetmyVariable() As Integer GetmyVariable = myVariable End Function 'In the control =GetmyVariable() 'Anywhere else Me!txtMyTextBox = myVariable Regards, Graham R Seach Microsoft Access MVP Sydney, Australia Microsoft Access 2003 VBA Programmer's Reference http://www.wiley.com/WileyCDA/WileyT...764559036.html "Alex via AccessMonster.com" wrote in message news:150591afa0ef4b0cb90aabcc25b9e2d6@AccessMonste r.com... I was cracking my head on this one yesterday, I need some examples of how to make a hidden form and to store a value there and refer to it from a field in another form. I managed to use AutoExe macro to open form and then run "WindowHide" command, it works, but the data is lost or nowhere to be stored. Thanks for any advice -- Message posted via http://www.accessmonster.com |
#3
|
|||
|
|||
Hi Graham, thanks for your reply
I followed your instructions, seems like a good idea, but Im getting "0" in the text box field, when it is supposed to be either 1,2,3 (depends on what I select from combo box). Its a log in form with cb with the code: --------- Private Sub Command5_Click() 'Check to see if data is entered into the UserName combo box If IsNull(Me.user_name) Or Me.user_name = "" Then MsgBox "You must enter a User Name.", vbOKOnly, "Required Data" Me.user_name.SetFocus Exit Sub End If 'Check to see if data is entered into the password box If IsNull(Me.user_password) Or Me.user_password = "" Then MsgBox "You must enter a Password.", vbOKOnly, "Required Data" Me.user_password.SetFocus Exit Sub End If 'Check value of password in tblEmployees to see if this matches value chosen in combo box If Me.user_password.Value = DLookup("user_password", "User", "[user_id] =" & Me.user_name.Value) Then Me.user_name.Value = myVariable 'Close logon form and open splash screen DoCmd.Close acForm, "User", acSaveNo DoCmd.OpenForm "MainMenu" Else MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!" Me.user_password.SetFocus End If 'If User Enters incorrect password 3 times database will shutdown intLogonAttempts = intLogonAttempts + 1 If intLogonAttempts 3 Then MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!" Application.Quit End If End Sub ---------------------- As you can see, I've got Me.user_name.Value = myVariable user_name is the name of the combo box. What must I look at to resolve "0" problem? I have no idea myself God bless me and all those who help people on this forum, this is the last problem I need to solve before the DB completely finished -- Message posted via http://www.accessmonster.com |
#4
|
|||
|
|||
Alex,
Here is a function that will take care of your situation. I avoid using public variables, and use something like this. If you pass no value, it will return the current value of varSaveVal, If you pass a value, it will update the value of varSaveVal. It will also return the same value passed. Function MyPubVar(Optional varPubVal As Variant) As Variant Static varSaveVal As Variant If Not IsMissing(varPubVal) Then varSaveVal = varPubVal End If MyPubVar = varSaveVal End Function "Alex via AccessMonster.com" wrote: Hi Graham, thanks for your reply I followed your instructions, seems like a good idea, but Im getting "0" in the text box field, when it is supposed to be either 1,2,3 (depends on what I select from combo box). Its a log in form with cb with the code: --------- Private Sub Command5_Click() 'Check to see if data is entered into the UserName combo box If IsNull(Me.user_name) Or Me.user_name = "" Then MsgBox "You must enter a User Name.", vbOKOnly, "Required Data" Me.user_name.SetFocus Exit Sub End If 'Check to see if data is entered into the password box If IsNull(Me.user_password) Or Me.user_password = "" Then MsgBox "You must enter a Password.", vbOKOnly, "Required Data" Me.user_password.SetFocus Exit Sub End If 'Check value of password in tblEmployees to see if this matches value chosen in combo box If Me.user_password.Value = DLookup("user_password", "User", "[user_id] =" & Me.user_name.Value) Then Me.user_name.Value = myVariable 'Close logon form and open splash screen DoCmd.Close acForm, "User", acSaveNo DoCmd.OpenForm "MainMenu" Else MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!" Me.user_password.SetFocus End If 'If User Enters incorrect password 3 times database will shutdown intLogonAttempts = intLogonAttempts + 1 If intLogonAttempts 3 Then MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!" Application.Quit End If End Sub ---------------------- As you can see, I've got Me.user_name.Value = myVariable user_name is the name of the combo box. What must I look at to resolve "0" problem? I have no idea myself God bless me and all those who help people on this forum, this is the last problem I need to solve before the DB completely finished -- Message posted via http://www.accessmonster.com |
#5
|
|||
|
|||
Alex,
Of course it's going to return 0, because you haven't set the variable to anything prior to reading it! But I fail to see why you need this variable anyway. In fact, if all you want to do is allow the user 3 attempts at logging in, then the following will do it: 'Declarations Section Private intLogonAttempts As Integer Private Sub Command5_Click() Dim rs As DAO.Recordset Dim sSQL As String If Len(Trim(Nz(Me.user_name, ""))) = 0 _ Or Len(Trim(Nz(Me.user_password, ""))) = 0 Then MsgBox "You must enter a Username and Password.", vbOKOnly, "Required Data" Me.user_name = "" Me.user_password = "" Me.user_name.SetFocus Else sSQL = "SELECT user_name, user_password " & _ "FROM [User] " & _ "WHERE user_id = """ & Me.user_name & _ """ AND user_password = """ & Me.user_password & """" Set rs = DBEngine(0)(0).OpenRecordset(sSQL, dbOpenSnapshot) If rs.AbsolutePosition -1 Then 'Allow the user to login Else intLoginAttempts = intLoginAttempts + 1 End If End If rs.Close Set rs = Nothing If (intLogonAttempts = 3) Then MsgBox "You do not have access to this database." & vbCrLf & vbCrLf & _ "Please contact your system administrator.", vbCritical, "Restricted Access!" Application.Quit End If End Sub Regards, Graham R Seach Microsoft Access MVP Sydney, Australia Microsoft Access 2003 VBA Programmer's Reference http://www.wiley.com/WileyCDA/WileyT...764559036.html "Alex via AccessMonster.com" wrote in message news:c5a35b251d9f446797963039aac951c7@AccessMonste r.com... Hi Graham, thanks for your reply I followed your instructions, seems like a good idea, but Im getting "0" in the text box field, when it is supposed to be either 1,2,3 (depends on what I select from combo box). Its a log in form with cb with the code: --------- Private Sub Command5_Click() 'Check to see if data is entered into the UserName combo box If IsNull(Me.user_name) Or Me.user_name = "" Then MsgBox "You must enter a User Name.", vbOKOnly, "Required Data" Me.user_name.SetFocus Exit Sub End If 'Check to see if data is entered into the password box If IsNull(Me.user_password) Or Me.user_password = "" Then MsgBox "You must enter a Password.", vbOKOnly, "Required Data" Me.user_password.SetFocus Exit Sub End If 'Check value of password in tblEmployees to see if this matches value chosen in combo box If Me.user_password.Value = DLookup("user_password", "User", "[user_id] =" & Me.user_name.Value) Then Me.user_name.Value = myVariable 'Close logon form and open splash screen DoCmd.Close acForm, "User", acSaveNo DoCmd.OpenForm "MainMenu" Else MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!" Me.user_password.SetFocus End If 'If User Enters incorrect password 3 times database will shutdown intLogonAttempts = intLogonAttempts + 1 If intLogonAttempts 3 Then MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!" Application.Quit End If End Sub ---------------------- As you can see, I've got Me.user_name.Value = myVariable user_name is the name of the combo box. What must I look at to resolve "0" problem? I have no idea myself God bless me and all those who help people on this forum, this is the last problem I need to solve before the DB completely finished -- Message posted via http://www.accessmonster.com |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
hidden form won't stay hidden | Bill Reed via AccessMonster.com | New Users | 3 | May 18th, 2005 04:10 PM |
Hidden Records on Form | Caleb | Using Forms | 1 | April 21st, 2005 10:07 PM |
Using a from to make a record hidden | Andy P | Using Forms | 7 | August 11th, 2004 03:40 AM |
synchronizing form and list box | Deb Smith | Using Forms | 8 | June 21st, 2004 08:15 PM |