need help for VBA code(MS Access)

Hi all,

I need your kindly help.

My MS Access Form needs a function like this: I have three text box and one button. When I click button first time, the 1st text box will display the current time . When I click button second time, the 2nd text box will display the current time. the same with 3rd text box .

Does VBA code can do this? It would be greatly appreciated for any help

reagrds,
Nancy

[407 byte] By [nancywhite] at [2008-2-28]
# 1

Nancy,

Declare a static variable on the click event - Something like this:
Private Sub Button1_Click()
Static intx As Integer
intx = intx + 1
Select Case intx
Case 1
TextBox1.Text = Now
'if you wish to clear the other boxes do it here

Case 2
TextBox2.Text = Now
'if you wish to clear the other boxes do it here
'ie. textbox1.text=""

Case 3
TextBox3.Text = Now
'if you wish to clear the other boxes do it here
End Select
End Sub

Ness22 at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 2
Hi Nancy,

Here's some additional info from our support engineer:

I wrote a piece of code to realize the feature mention by our buddy.

======================================

Option Compare Database

Dim iClick As Integer ‘Global variable to record the click count

Private Sub btClick_Click()

Select Case iClick Mod 3

Case 0:

With Me

.labA.Visible = True

.txtA.Visible = True

.labB.Visible = False

.txtB.Visible = False

.labC.Visible = False

.txtC.Visible = False

End With

Case 1:

With Me

.labA.Visible = False

.txtA.Visible = False

.labB.Visible = True

.txtB.Visible = True

.labC.Visible = False

.txtC.Visible = False

End With

Case 2:

With Me

.labA.Visible = False

.txtA.Visible = False

.labB.Visible = False

.txtB.Visible = False

.labC.Visible = True

.txtC.Visible = True

End With

End Select

iClick = iClick + 1

If (iClick > 2) Then iClick = 0 ‘To avoid exceeding the boundary of integer type

End Sub

Private Sub Form_Load()

With Me

.labA.Visible = False

.txtA.Visible = False

.labB.Visible = False

.txtB.Visible = False

.labC.Visible = False

.txtC.Visible = False

End With

iClick = 0

End Sub

==========================================

thanks,
-brenda (ISV Buddy Team)

MSISVBuddyTeam at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 3
assuming your text fields are locked, you could forgo the variable alltogether:

Private Sub btnYourButton_Click()

If IsNull(txtDate1) Then
txtDate1 = now()
ElseIf IsNull(txtDate2) Then
txtDate2 = now()
Else
txtDate3 = now()
End If

End Sub

mnTeddy at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...