Registry Save and Get Problem

pingme89

Board Regular
Joined
Jan 23, 2014
Messages
176
Office Version
  1. 365
Platform
  1. Windows
I have the following code that runs when the spreadsheet is open.

I have a type mismatch on the date portion when I try to set a default date if there is no data exists in that registry entry.

I am sure this must be a simple mistake, but I can't figure out what I am doing wrong. Preferably, I would like the format of the Registry Entry as a Date not a String.

Private Sub Workbook_Open()
Dim Rname as String
Dim Ddate as Date
GetSetting "PITB", "User Settings", "Full Name", ""
GetSetting "PITB", "User Settings", "Expiry", "3/30/2016"
Rem SaveSetting "PITB", "User Settings", "Full Name", "John Doe"
Rem SaveSetting "PITB", "User Settings", "Expiry", ""
RName = GetSetting("PITB", "User Settings", "Full Name")
Ddate = GetSetting("PITB", "User Settings", "Expiry")




MsgBox RName & Ddate




ActiveWindow.WindowState = xlMinimized
Rem SetRestrictions.Show
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,
see if this update to your code helps:

Code:
Dim dDate As Date
Dim DefaultDate As String


DefaultDate = "3/30/2016"


dDate = DateValue(GetSetting("PITB", "User Settings", "Expiry", DefaultDate))

MsgBox dDate

DateValue Function will coerce string date to valid date data type to pass to your dDate variable.

Dave
 
Upvote 0
Hi,
see if this update to your code helps:

Code:
Dim dDate As Date
Dim DefaultDate As String


DefaultDate = "3/30/2016"


dDate = DateValue(GetSetting("PITB", "User Settings", "Expiry", DefaultDate))

MsgBox dDate

DateValue Function will coerce string date to valid date data type to pass to your dDate variable.

Dave


I get a Run-Time Error 13. Type Mismatch
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

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