Using Two Different Textboxes to Update One Field

R

R Tanner

Hi,

I have to give you guys all a very big hand cause I came into this
Access thing not very long ago and I didn't know ANYTHING. I didn't
even realize the difference between Access and Excel. I am far from
an expert now, but I have learned a ton and it is largely due to
everyone in these news groups. So thank you very much.

Onto my question. I have a form with 17 different fields, some of
which are required and some of which aren't. In my form, I have a
start and end time. These represent two different fields in my
table. I would like to separate them out and have the user enter the
start date, start time, end date, and end time in four different boxes
in my form. I am not sure what the best way to go about this would
be. I'm guessing some type of query...or maybe I should do it in the
expression builder or something?

Thanks
 
R

R Tanner

Hi,

I have to give you guys all a very big hand cause I came into this
Access thing not very long ago and I didn't know ANYTHING.  I didn't
even realize the difference between Access and Excel.  I am far from
an expert now, but I have learned a ton and it is largely due to
everyone in these news groups.  So thank you very much.

Onto my question.  I have a form with 17 different fields, some of
which are required and some of which aren't.  In my form, I have a
start and end time.  These represent two different fields in my
table.  I would like to separate them out and have the user enter the
start date, start time, end date, and end time in four different boxes
in my form.  I am not sure what the best way to go about this would
be.  I'm guessing some type of query...or maybe I should do it in the
expression builder or something?

Thanks

What I have been trying to do is enter event code in the afterupdate
procedure to update the textbox with the value of both my start date
and start time fields...like so...The weird thing is that the textbox
only updates after I enter text in SD....


Private Sub ST_AfterUpdate()

StartDateAndTime.Value=ST.Value & " " & SD.Value

End Sub

Private Sub SD_AfterUpdate()

StartDateAndTime.Value=SD.Value & " " & ST.Value

End Sub
 
J

John W. Vinson

Hi,

I have to give you guys all a very big hand cause I came into this
Access thing not very long ago and I didn't know ANYTHING. I didn't
even realize the difference between Access and Excel. I am far from
an expert now, but I have learned a ton and it is largely due to
everyone in these news groups. So thank you very much.

Onto my question. I have a form with 17 different fields, some of
which are required and some of which aren't. In my form, I have a
start and end time. These represent two different fields in my
table. I would like to separate them out and have the user enter the
start date, start time, end date, and end time in four different boxes
in my form. I am not sure what the best way to go about this would
be. I'm guessing some type of query...or maybe I should do it in the
expression builder or something?

Thanks

Well... WHY?

What good is it to edit four textboxes when you can accomplish exactly the
same task by editing two?

Oh, you can do it with a bit of VBA code, and some additional complexity: you
would need SIX textboxes on the form, and VBA code in the form's Current event
and in the AfterUpdate events of the four time only/date only textboxes. But
I'm trying to understand what benefit you would get from doing so!
 
R

R Tanner

Hi,

I have to give you guys all a very big hand cause I came into this
Access thing not very long ago and I didn't know ANYTHING.  I didn't
even realize the difference between Access and Excel.  I am far from
an expert now, but I have learned a ton and it is largely due to
everyone in these news groups.  So thank you very much.

Onto my question.  I have a form with 17 different fields, some of
which are required and some of which aren't.  In my form, I have a
start and end time.  These represent two different fields in my
table.  I would like to separate them out and have the user enter the
start date, start time, end date, and end time in four different boxes
in my form.  I am not sure what the best way to go about this would
be.  I'm guessing some type of query...or maybe I should do it in the
expression builder or something?

Thanks

Okay I don't know what was wrong. I just deleted the little script
and re-wrote it and it worked fine. I guess to clarify my question,
it would be how to make an unbound textbox update a field in a
table...If my textbox is bound the AfterUpdate event procedure doesn't
enter the date and time into it...Any ideas?
 
J

John W. Vinson

Okay I don't know what was wrong. I just deleted the little script
and re-wrote it and it worked fine. I guess to clarify my question,
it would be how to make an unbound textbox update a field in a
table...If my textbox is bound the AfterUpdate event procedure doesn't
enter the date and time into it...Any ideas?

Three textboxes:

StartDate: unbound, i.e. Control Source is blank
StartTime: unbound, ditto
StartDateTime: bound to Start; this can be set to Visible=No if you don't want
users getting confused.

In the AfterUpdate event of StartDate put code like:

Private Sub StartDate_AfterUpdate()
If Not IsNull(Me!StartDate) Then
Me!StartDateTime = CDate(Me!StartDate) + CDate(NZ(Me!StartTime, "00:00"))
End If
End Sub

In the AfterUpdate event of StartTime put

Private Sub StartTime_AfterUpdate()
If Not IsNull(Me!StartTime) Then
Me!StartDateTime = CDate(NZ(Me!StartDate, "1/1/1900")) _
+ CDate(NZ(Me!StartTime, "00:00"))
End If
End Sub

Then in the Form's Current event, fill in the unbound boxes from the stored
date/time value:

Private Sub Form_Current()
If Not IsNull(Me!Start) Then
Me!StartDate = DateValue(Me!Start)
Me!StartTime = TimeValue(Me!Start)
Else
Me!StartDate = ""
Me!StartTime = ""
End If
End Sub

This will fill in Start; if the user leaves StartDate blank it will put in
January 1, 1900 (you can choose some more appropriate date if you want, maybe
use Date() in place of "1/1/1900"; if the user leaves StartTime blank it will
put in midnight (and again you can choose some other appropriate value).

I still feel that you're making a mistake by separating these, but it's your
database!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top