Welcome to the skill header Forums. You can ask questions, get help, or help other members out. Join our Forum for free.

Notifications
Clear all

Help Needed!

6 Posts
3 Users
3 Reactions
160 Views
Posts: 8
Topic starter
(@quadcrazi)
Active Member
Joined: 6 months ago

Hello!

I am creating a database for our family business and this tutorial has already been life changing!

However, I am having an issue writing the code for the 'Main Dashboard> Event> On Load'

I am getting an error with 'rstPrf'

I can't find where this is supposed to refer to in order to check spelling etc. (I had this issue once already)

Please help! I am only on the first tutorial video but can't wait to finish the rest once this problem is resolved!

Thanks in advance,

Tamara

Topic Tags
5 Replies
FStetson
Posts: 59
(@fstetson)
Trusted Member
Joined: 8 months ago

Because you are using "Options Explicit" like I do in all my VBA code.  You need to DIM the record set before it will recognize it.  

Try changing your code to:

Private Sub Form_Load()

Dim rstPrf As Recordset
Set rstPrf = CurrentDb.OpenRecordset("tbl_profile", dbOpenDynaset, dbSeeChanges)
With rstPrf
.FindFirst "prfID=" & aprofile
If .Fields("prfDashboard") = 0 Then Me.NavigationButton11.Enabled = False
If .Fields("prfAnalysis") = 0 Then Me.NavigationButton13.Enabled = False
If .Fields("prfSales") = 0 Then Me.NavigationButton15.Enabled = False
If .Fields("prfPurchase") = 0 Then Me.NavigationButton17.Enabled = False
If .Fields("prfProducts") = 0 Then Me.NavigationButton19.Enabled = False
If .Fields("prfStock") = 0 Then Me.NavigationButton21.Enabled = False
If .Fields("prfEmployees") = 0 Then Me.NavigationButton23.Enabled = False
If .Fields("prfAccounts") = 0 Then Me.NavigationButton25.Enabled = False
If .Fields("prfPreferences") = 0 Then Me.NavigationButton27.Enabled = False
End With
Set rstPrf = Nothing

 

Reply
1 Reply
(@quadcrazi)
Joined: 6 months ago

Active Member
Posts: 8

@fstetson Fixed! Thank you so much!

Reply
FStetson
Posts: 59
(@fstetson)
Trusted Member
Joined: 8 months ago

Hope this helps.  Here is a link to MS Learning DIM Statement

Reply
Posts: 18
 ursh
Admin
(@ursh)
Member
Joined: 1 year ago

Keep the Public Variable declaration separate from the Main Dashboard Form in a Module with "Option Explicit" and keep the rest of the code from the On Click Event of the Main Dashboard Form without "Option Explicit".

Reply
FStetson
Posts: 59
(@fstetson)
Trusted Member
Joined: 8 months ago

While Ursh is the real expert here and with every ounce of respect I have for him, I have to disagree.  While this appears to be a personal preference issue, there are some good arguments for both sides.  The two best articles I could find for you in order to view both perspectives can be found at:

Implicit and Explicit Declaration: Best Practices: Implicit vs Explicit Variable Declaration in VBA - FasterCapital

Reliable Excel VBA Code: Best Practices - Master Office VBA

Again, this is my preference that I have based on experience.  So, when I am responding I do come from that viewpoint.  Happy Coding everyone!

Reply
Share: