Question

how to input the date and time to MS access by hitting a pushbutton at matlab figure?

enter image description here

my code for the date and time checkbox is:

m=1;
while m==1
m=get(hObject,'value');
txt=datestr(now);
set(handles.text7,'string',txt);
pause(1);
end

That code is located at a checkbox and date&time appears at static text. What I wanted to do is insert a pushbutton and whenever I will hit the pushbutton, It will be sent to the database table as an input but I don't know how to sync MS access to MatLab. Please help me because I'm very troubled right now :( Thank you in advance!

Was it helpful?

Solution 2

I finally made the connection of matlab and ms access. Here's the tutorial on how to configure the connection first.

After successfully making a connection, I used this code on a callback.

conn = database('databasename','username','password');
dbpath = 'C:\Users\______.mdb'; %insert database path
tableName = 'datetime'; %insert tablename here in MSAccess
colname = {'column1'} %column of your tables in MsAccess
date = datestr(now); %the string of date and time
coldata = {date}
insert(conn,tableName,colname,coldata); %will insert the data to the database.
close(conn);

OTHER TIPS

You can use the clipboard to establish a basic communication from Matlab to MS Access.

Matlab part - The button's callback function would populate the clipboard by the actual date and time. This is acheived with the code:

clipboard('copy', datestr(now));

Each time the button is pushed, the clipboard content will change.

MS Access part You can access the clipboard text content with the following

Dim MyData As DataObject
Dim strClip As String
Set MyData = New DataObject
MyData.GetFromClipboard
strClip = MyData.GetText

You can monitor the clipboard changes with a timer (see this SO for example).

You may alternatively populate a dedicated text file as the clipboard may be used by other processes or user actions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top