Could someone please help me with a coding glitch (crossposted)?

KristenB

New member
Joined
Jan 2, 2020
Messages
35
Reaction score
0
Points
0
Excel Version(s)
365
I have a userform with checkboxes for each meal that a user is eligible to receive reimbursement for based on time calculations on my database. All of that is working appropriately, however, I have posted to another forum requesting assistance to lock down a checkbox if it isn't populated with a checkmark so the user isn't able to select it because the meal isn't allowed. The other forum user and I have tried several things and nothing seems to be working. I have confidence in him and I have no doubt that he is more than capable to answer, and it doesn't seem that the solution should be difficult, but I am also still new at VBA coding, so I am assuming that I am not relaying the information correctly? Here is the link to the 'crosspost' so you can see what has been done already: https://stackoverflow.com/questions/59721077/userform-checkbox-questions I will gladly post the solution to my problem to that forum if someone here can assist me and if that is proper protocol.

Here is the current coding that isn't working properly:

Code:
 Private Sub txtArrivalTime_AfterUpdate()'When time is entered, time transfers immediately to spreadsheet datafield and sends back to userform which meals are allowed.


Dim TargetRow As Integer
TargetRow = Sheets("Codes").Range("D43").Value + 1


With Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 26)
 .Value = TimeValue(txtArrivalTime)
 .NumberFormat = "hh:mm" 'arrival time
End With


'''MEALS ALLOWED PER SPREADSHEET TO USERFORM'''
If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 28).Value = "T" Then
frmUserTravel.chkMorning = Checked
End If


If frmUserTravel.chkMorning = Unchecked Then
   frmUserTravel.chkMorning.Enabled = False
End If


If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 30).Value = "T" Then
frmUserTravel.chkMidday = Checked
End If


If frmUserTravel.chkMidday = Unchecked Then
   frmUserTravel.chkMidday.Enabled = False
End If


If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 32).Value = "T" Then
frmUserTravel.chkEvening = Checked
End If


If frmUserTravel.chkEvening = Unchecked Then
   frmUserTravel.chkMidday.Enabled = False
End If
'''END MOVEMENT OF MEALS ALLOWED TO USERFORM'''


End Sub
 
I don't understand what I missed? I noted that it was crossposted, I included the link, I stated that I had not received a working solution, I was respectful of all, would you please tell me what I missed?
 
You suggested you weren't sure ("if that is proper protocol"). Sorry if I misinterpreted the comment.
 
Hello KristenB

The problem with showing us code that isn't working is that we don't know what it isn't working with.
Any chance of you supplying a sample workbook indicative of what you're working with so anyone willing to assist doesn't have to guess at anything
and can test possible solutions rather than posting something that you have to troubleshoot ?
 
I can do that but please be aware, I have some code that I have commented out in my vba... I will remove it when I am completely finished but didn't want to remove it in the event I need it again. Also, I have taken a few hidden pages out of the form and removed some information to maintain confidentiality. So if something else doesn't work right, I'm sorry. :(
 

Attachments

  • TravelForm ForumCopy01152020.xlsm
    80.9 KB · Views: 9
@AliGW Okay... I just wanted to be sure if I was doing something wrong that I understood what. :) Thank you.
 
Does this get you any closer to what you're looking for
Code:
Private Sub txtArrivalTime_AfterUpdate()
' When time is entered, time transfers immediately to spreadsheet datafield and sends back to userform which meals are allowed.

Dim TargetRow As Integer
TargetRow = Sheets("Codes").Range("D43").Value + 1

With Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 26)
 .Value = TimeValue(txtArrivalTime)
 .NumberFormat = "hh:mm" 'arrival time
End With

'''MEALS ALLOWED PER SPREADSHEET TO USERFORM'''
With Me.chkMorning
    If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 28).Value = "T" Then
        .Value = Checked
    Else
        .Value = Unchecked
        .Enabled = False
    End If
End With

With Me.chkMidday
    If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 30).Value = "T" Then
        .Value = Checked
    Else
        .Value = Unchecked
        .Enabled = False
    End If
End With

With Me.chkEvening
    If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 32).Value = "T" Then
        .Value = Checked
    Else
        .Value = Unchecked
        .Enabled = False
    End If
End With

'''END MOVEMENT OF MEALS ALLOWED TO USERFORM'''

End Sub
 
Exactly what I needed! :) Thank you so much!!
 
Back
Top