Learning VBA: Userform issue

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,584
Office Version
  1. 365
Platform
  1. Windows
the line highlighted in red gives error "Invalid Qualifier".
I have created a Userform for filling data. Below is the screenshot of it.

1584950279794.png


Rich (BB code):
Dim everythingfilledin  As Boolean
everythingfilledin = True

For Each c In Me.Controls
    If TypeOf c Is msforms.TextBox Then
        If c.Value = "" Then
            c.BackColor = rgbPink
            everythingfilledin = False
        Else
            c.BackColor = rgbWhite
        End If
      End If
Next c
If Not everythingfilledin Then Exit Sub

If Not IsDate(DOB.Value) Then
    MsgBox "PLEASE ENTER A VALID DATE.", vbCritical
    DOB.SetFocus
    Exit Sub
Else
    DOB.BackColor = rgbWhite
End If

With Sheet2.Range("A1048576").End(xlUp)
    .Offset(1, 0).Value = Name.Value
    .Offset(1, 1).Value = DOB.Value
    .Offset(1, 2).Value = Gender.Value
    .Offset(1, 3).Value = PartnerGender.Value
End With

MsgBox "Thanks, " & Name.Value & ", Your application was successful!", vbInformation
Unload Me

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi,
I suspect error could be due to Name may be a VBA reserved word - try renaming your TextBox control & see if resolves for you

VBA Code:
.Offset(1, 0).Value = txtName.Value

Dave
 
Upvote 0
Hi,
I suspect error could be due to Name may be a VBA reserved word - try renaming your TextBox control & see if resolves for you
Dave
Well Spotted. Pure Genius!!
Thank you so much.
I was frustrated trying to figure out the reason for such a long time.
 
Upvote 0
You are welcome
You can include a reserved word in your naming convention for Control or Variable names but to avoid conflicts, just include a prefix with one that defines the control or data type

eg for combobox you could prefix with cmb

VBA Code:
.Offset(1, 0).Value = cmbName.Value

same with variables you can prefix with data type

VBA Code:
Dim strName As String



Hope Helpful

Dave
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top