How to have value fill in the form without clicking on the textbox (1 Viewer)

Happyz

Registered User.
Local time
Today, 12:45
Joined
Nov 25, 2017
Messages
22
Hello all, I would like the form to auto populate my result in the textbox without me having to click on it to display the textbox. How can i do that? By the way, I am currently using unbound form.

What i am currently doing now is that i write a VBA code to help me differentiate if this is oversea or local branch based on the country.

My code that i put inside my branch textbox on the form:

Code:
Private Sub txtBranch_Click()
Dim Branch As String
Dim Country As String
Country = Me.txtCountry
If Me.txtCountry = "Singapore" Then
    Me.txtBranch = "Local"
Else
    Me.txtBranch = "Oversea"
End If
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:45
Joined
May 7, 2009
Messages
19,246
Use Current Event of the Form and BeforeUpdate event of txtCountry:



Private Sub Form_Current()
Me.txtBranch = Switch(Me.txtCountry="Singapore","Local",True,"Oversea")
End Sub


Private Sub txtCountry_BeforeUpdate(Cancel As Integer)
Call Form_Current
End Sub
 

Happyz

Registered User.
Local time
Today, 12:45
Joined
Nov 25, 2017
Messages
22
Use Current Event of the Form and BeforeUpdate event of txtCountry:



Private Sub Form_Current()
Me.txtBranch = Switch(Me.txtCountry="Singapore","Local",True,"Oversea")
End Sub


Private Sub txtCountry_BeforeUpdate(Cancel As Integer)
Call Form_Current
End Sub



Hi,

for the branch fill, the fill is always oversea, even before i select any data.
my plan is to have all the fills empty, and then when i edit a line of data, all the data will then be added in to the respective fills.

for now, all of the branches are oversea. the right condition for the branch fill would be:

if country = singapore, then branch = local,
else, branch = oversea

but i am not able to put it correctly. hope you can help me! thank you:)
 

Attachments

  • Oversea Fill.png
    Oversea Fill.png
    44.4 KB · Views: 306

Mark_

Longboard on the internet
Local time
Today, 12:45
Joined
Sep 12, 2017
Messages
2,111
Put arnelgp's code in the After_accept for the Country field. This way you only fill it in once you've entered data.
 

Happyz

Registered User.
Local time
Today, 12:45
Joined
Nov 25, 2017
Messages
22
Put arnelgp's code in the After_accept for the Country field. This way you only fill it in once you've entered data.


Hi,

I thank you for your help, but i do not really understand your reply. It would be great if you could give me a clearer explanation! Thank you once again:)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:45
Joined
May 7, 2009
Messages
19,246
try this one:
Code:
Private Sub txtCountry_BeforeUpdate()
If Trim(Me.txtCountry & "")<> "" Then
	Me.txtBranch = IIF(Me.txtCountry="Singapore","Local","Oversea")
Else
	Me.txtBranch=Null
End If
End Sub

Private Sub txtBranch_GotFocus()
If Trim(Me.txtBranch & "")="" And Trim(Me.txtCountry & "") <> "" Then _
	Call txtCountry_BeforeUpdate
End Sub
 

Happyz

Registered User.
Local time
Today, 12:45
Joined
Nov 25, 2017
Messages
22
try this one:
Code:
Private Sub txtCountry_BeforeUpdate()
If Trim(Me.txtCountry & "")<> "" Then
	Me.txtBranch = IIF(Me.txtCountry="Singapore","Local","Oversea")
Else
	Me.txtBranch=Null
End If
End Sub

Private Sub txtBranch_GotFocus()
If Trim(Me.txtBranch & "")="" And Trim(Me.txtCountry & "") <> "" Then _
	Call txtCountry_BeforeUpdate
End Sub


Hi Arnelgp,

Thanks for your help. I appreciate it a lot. However, there is another error message that came out after amending the codes you've written. I have attached the error above. Hope you could clarify it with me. Thank you:)
 

Attachments

  • Error Message.png
    Error Message.png
    23 KB · Views: 342

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:45
Joined
May 7, 2009
Messages
19,246
like the msg says, its on yhe Click event of your control. i dont have it in my code. if you can post the code.
 

Users who are viewing this thread

Top Bottom