Cannot seem to get the value from text box in another form..

pr2-eugin

Super Moderator
Local time
Today, 15:55
Joined
Nov 30, 2011
Messages
8,487
Hello I am trying to access a text field placed in another form. but i could not use it. All i wanted to was.. if the date entered in the form is less than today's date, the user needs to alter it.. else the management should come and override it by granting it permission to put a older date.. the following is the condition..

Private Sub START_DATE_BeforeUpdate(Cancel As Integer)
If [START DATE].Value <= Date - 7 Then
msg = "Please contact Management. Press OK to override, Cancel to edit date"
Val = MsgBox(msg, vbOKCancel)
If Val = 1 Then
typ = PasswordInputBox("Enter the password to proceed")
If typ = "grant" Then
MsgBox ("SUCESS")
Else
MsgBox ("VERIFICATION Failed !")
[START DATE].DefaultValue = Date
End If
Else
[START DATE].DefaultValue = Date
End If
End If
End Sub

I also want the default valure of this start date field to be todays date.. which does not seem to be working either..

I also want the default valure of this start date field to be todays date..
The PasswordInputBox is a user defined function as I needed a password field input box.. the following is the code for it..

Function PasswordInputBox( _
Prompt As String, _
Optional TITLE As String = vbNullString, _
Optional Default As String = vbNullString _
) As String

Dim strOpenArgs As String

strOpenArgs = "Prompt=" & Prompt
If Len(TITLE) > 0 Then
strOpenArgs = strOpenArgs & "~Title=" & TITLE
End If
If Len(Default) > 0 Then
strOpenArgs = strOpenArgs & "~Default=" & Default
End If

DoCmd.OpenForm FormName:="frmInputBox_Password", _
View:=acNormal, _
WindowMode:=acDialog
If CurrentProject.AllForms("frmInputBox_Password").Is Loaded Then
PasswordInputBox = Forms![frmInputBox_Password]!Text3
DoCmd.Close acForm, "frmInputBox_Password"
Else
PasswordInputBox = vbNullString
End If

End Function

the highlighted line is where i want to return whatever is entered into the field.. the following line also does not seem to work.. once OK is pressed it needs to close which is not happening.. please someone help me..

I can provide the coding for the other form if it is necessary..
 
forms![name of form].control.value,caption,text etc

example

Code:
dim customer as string
 
customer = forms![PO Main].POCustomer.value

would return the value from the controlsource POCustomer on the PO Main form

I find it very important to include the .value or .text at the end to pull the data. Also make sure that form you are pulling from is actually opened still.

try that and see what you get
 
Thanks josephff I did try that earlier.. I believe the line

PasswordInputBox = Forms![frmInputBox_Password]!Text3.Value is not even executed.. to be more precise.. the if condition is not executed.. i tried to put a msgbox immediately after the if.. the msg box did not appear.. but when i tried to take the format of how the form should open from

DoCmd.OpenForm FormName:="frmInputBox_Password", _
View:=acNormal, _
WindowMode:=acDialog, _
OpenArgs:=strOpenArgs

to

DoCmd.OpenForm FormName:="frmInputBox_Password"

the form exits on loading.. does this make any sense at all?? or am i loosing my mind??
 
Solved.. Thanks... I did not see the variable names properly.. it works fine now..
 

Users who are viewing this thread

Back
Top Bottom