Return a value from either a textbox or option control

G

Guest

I've been trying to figure this out and think I have completely confused
myself on it.

I need to return a value from one of two controls, either the textbox or the
option group, depending on which one has the value. The textbox returns a
value from a calendar ActiveX object and the option group has four radio
buttons.

The user completes the form to add a record then clicks submit. Submit
launches a read only form to confirm the data record, which is where I need
to capture the value from one of the two control'.

I'm having an issue on how to go about capturing the value for the option
group and translating it into a text value, ie. 1 = TBD, 2 = Maintenance.

Your help is appreciated!!!!
 
D

Douglas J. Steele

Need to return a value where? In a query, in VBA code?

You can try using the Nz function along the lines of

Nz(Forms!NameOfForm!NameOfCalendarControl,
Forms!NameOfForm,NameOfOptionGroup)

To translate from a number to a value, take a look at the Choose function:

Choose(Forms!NameOfForm,NameOfOptionGroup, "TBD", "Maintenance", ...)
 
G

Guest

Here's what I have so far, though i know I'm missing something...

I get a error on the date = source lines.... null error.

Private Sub Form_Open(Cancel As Integer)

Dim fdate As String
Dim date1 As String
Dim date2 As String

date1 = Forms!fmnewproject2.txtDate.Value
date2 = Forms!fmnewproject2.frmDate.Value

If date1 = Not Null Then
fdate = date1
ElseIf date2 = Not Null Then
fdate = date2
If date2 = 1 Then
fdate = "TBD"
ElseIf date2 = 2 Then
fdate = "Multi"
ElseIf date2 = 3 Then
fdate = "Ongoing"
ElseIf date2 = 4 Then
fdate = "Maintenance"
End If
ElseIf date1 = Null Then
End
ElseIf date2 = Null Then
End
End If


txtDate.Value = fdate

End Sub
 
D

Douglas J. Steele

Null is a very special case: you cannot use standard comparisons with it

If IsNull(date1) = False Then
fdate = date1
ElseIf IsNull(date2) = False Then

There's really no need for the

ElseIf date1 = Null Then
End
ElseIf date2 = Null Then
End

code, since it's not really doing anything, but if you did have something to
do in those cases, you'd need something like:

ElseIf IsNull(date1) =True Then
End
ElseIf IsNull(date2) = True Then
End

However, what makes more sense is something like:

If IsNull(date1) = False Then

Else
If IsNull(date2) = False Then

Else
' If you get to this section of the code,
' you know that both date1 and date2 are Null.
End If
End If


BTW, use of the End statement is seldom a good idea: the End statement stops
code execution abruptly, without invoking the Unload, QueryUnload, or
Terminate event, or any other Visual Basic code.. In other words, it doesn't
provide a "clean" end to execution. It's kind of like unplugging your
computer to turn it off, rather than clicking on the ShutDown button.
 
G

Guest

Thanks Doug, looks like NZ was the ticket.

Here's my final code for what I needed.

Private Sub Form_Open(Cancel As Integer)

Dim fdate As String
Dim date1 As Variant
Dim date2 As Variant

date1 = Forms!fmnewproject2.txtDate.Value
date2 = Forms!fmnewproject2.frmDate.Value

If Nz(date1, 0) <> 0 Then
fdate = date1
ElseIf Nz(date2, 0) <> 0 Then
fdate = date2
If date2 = 1 Then
fdate = "TBD"
ElseIf date2 = 2 Then
fdate = "Multi"
ElseIf date2 = 3 Then
fdate = "Ongoing"
ElseIf date2 = 4 Then
fdate = "Maintenance"
End If

End If

Forms!frmRproject.txtDate.Value = fdate


End Sub
 

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